uniq
- Eliminate Duplicate Linesdiff
- Differences between Filesfile
- See the File Typedate
- Get the Date and Timewhich
- Finding a Program Filewhereis
- Finding Files Used by a Programlocate
- Search for Any Filewho
- See Users Logged Onfinger
- Get information on Usersbzip2
gzip
- the GNU Compression Utilitytar
- Packaging Files for Transfer or StorageYou can connect to Gradescope to take weekly graded quiz today during the last 15 minutes of the class.
Once you start the quiz you have 15 minutes to finish it.
You can only take this quiz today.
There is not makeup for the weekly quiz because Gradescope does not permit it.
If you have the textbook you should read chapter 4 of Sobell, The Filesystem.
I have posted Homework 4 here.
As usual, it will be due next Sunday at 11:59 PM.
Are there any questions before I begin?
ssh
window open at any one timenano
to create the homework script file # Step 1
~ghoffman/it244_test/step_comment_check.sh
$ ~ghoffman/it244_test/step_comment_check.sh Usage: step_comment_check.sh USERNAME HW_NUMBER
$ ~ghoffman/it244_test/step_comment_check.sh ghoffman 3 # Step 1 # Step 2 # Step 3 # Step 4 # Step 5 # Step 6 # Step 7 # Step 8
cat
at the beginning of a
pipeline when it is not needed
cat
to create input sent to the following commands
grep
sort
head
tail
cat
in a pipe with these commands ...cat names.txt | grep Glenn cat names.txt | sort cat names.txt | head cat names.txt | tail
grep Glenn names.txt sort names.txt head names.txt tail names.txt
grep
more than once in a pipeline ...grep
gets one argument grep Win red_sox.txt | grep vs
grep Win red_sox.txt | grep vs red_sox.txt # WRONG
grep
will be thrown away ...grep
ghoffman@itserver6:~/it244/work$
$ head -5 red_sox.txt
2011-07-31 Red Sox @ White Sox Win 5-3
2011-07-02 Red Sox @ Astros Win 7-5
2011-07-03 Red Sox @ Astros Win 2-1
2011-07-04 Red Sox vs Blue Jays Loss 7-9
2011-07-05 Red Sox vs Blue Jays Win 3-2
$ head -5 red_sox.txt | sort
2011-07-02 Red Sox @ Astros Win 7-5
2011-07-03 Red Sox @ Astros Win 2-1
2011-07-04 Red Sox vs Blue Jays Loss 7-9
2011-07-05 Red Sox vs Blue Jays Win 3-2
2011-07-31 Red Sox @ White Sox Win 5-
sort
does not have an argumentsort
requires an argument that specifies the file to sortuniq
- Eliminate Duplicate Linesuniq
prints the lines of a file, leaving out any adjacent lines that are identicalsort
into uniq
uniq -i
ignores case when looking for duplicate linesdiff
- Differences between Filesdiff
compares two files and notes their differencesdiff
was created for use with the patch
utilitydiff
with the -y option to get output that is easier to readfile
- See the File Typefile
utility can be used the determine the type of a file
$ file * class_notes.css: ASCII text common_unix_commands.html: HTML document text cs285L: directory emacs_cheat_sheet.html: HTML document text index.html: HTML document text it244: directory tips.html: HTML document text unix_cheat_sheet.html: HTML document text work.txt: ASCII text
date
- Get the Date and Timedate
command will give the time and the date
$ date Tue Aug 21 10:20:05 EDT 2012
$ date +"%Y-%m-%d"
2012-08-21
info
or man
to see the various formatting options date
provideswc
- Counting characterswc
counts the lines, words and characters in a file
$ cat lines.txt Line 1 Line 2 Line 3 Line 4 Line 5 $ wc lines.txt 5 10 35 lines.txt
wc
what to count
$ wc -c lines.txt 35 lines.txt $ wc -w lines.txt 10 lines.txt $ wc -l lines.txt 5 lines.txt
which
- Finding a Program Filewhich
gives the location of an executable fileless
is located we can run which
like this
$ which less /usr/bin/less
which
uses the PATH system variable to find the executable filewhereis
- Finding Files Used by a Programwhereis
is another program that can be used to locate program fileswhereis
takes a different approach than which
whereis
searches these locationswhereis
on the tar
utility we get more information than
which
returned
$ whereis tar tar: /bin/tar /usr/include/tar.h /usr/share/man/man1/tar.1.gz
man
uses to provide information about tar
locate
- Search for Any Filewhich
and whereis
only work on programslocate
can be used to find any filelocate
locate
will search on a partial file name
$ locate foot /etc/update-motd.d/99-footer /usr/share/doc/java-common/debian-java-faq/footnotes.html /usr/share/emacs/23.3/lisp/mail/footnote.elc /usr/share/emacs/23.3/lisp/org/org-footnote.elc /usr/share/libparse-debianchangelog-perl/footer.tmpl /usr/share/xml-core/catalog.footer /usr/src/linux-headers-3.0.0-12/arch/arm/mach-footbridge /usr/src/linux-headers-3.0.0-12/arch/arm/mach-footbridge/Kconfig /usr/src/linux-headers-3.0.0-12/arch/arm/mach-footbridge/Makefile /usr/src/linux-headers-3.0.0-12/arch/arm/mach-footbridge/Makefile.boot /usr/src/linux-headers-3.0.0-12/arch/arm/mach-footbridge/include /usr/src/linux-headers-3.0.0-12/arch/arm/mach-footbridge/include/mach /usr/src/linux-headers-3.0.0-12/arch/arm/mach-footbridge/include/mach/debug-macro.S ...
locate
does not actually search the file system itselfupdatedb
updatedb
is usually run automatically in the background to update the databasewho
- See Users Logged Onwho
prints a list of all users currently on the machine
$ who offner pts/0 2019-07-30 07:38 (50.200.93.68) rickm pts/1 2019-07-26 17:05 (192.168.105.41) grullnor pts/2 2019-08-06 16:04 (192.168.107.156) ldavid pts/3 2019-07-31 07:47 (158.121.23.66) ...
who
also provides information about each user's login sessionwho am i
will show the user who is logged into a terminal
$ who am i ghoffman pts/0 2012-08-12 13:41 (dsl092-066-161.bos1.dsl.speakeasy.net)
finger
- Get information on Usersfinger
provides information about a user account
$ finger ghoffman Login: ghoffman Name: Glenn Hoffman Directory: /home/ghoffman Shell: /bin/bash On since Wed Aug 7 07:06 (EDT) on pts/5 from 209.6.202.123 8 hours 21 minutes idle On since Wed Aug 7 19:21 (EDT) on pts/19 from 209.6.202.123 2 seconds idle Mail forwarded to glennhoffman@mac.com Mail last read Mon Jul 15 10:58 2019 (EDT) Plan: Office: McCormack 3-0201-22 (Pterosaur poster on door) Office Hours: Tuesday & Thursday, 11:OO AM - 12:00 PM and 5:30 to 6:30 PM Classes: IT 116-1 Introduction to Scripting TuTh 12:30 - 1:45 PM Wheatley 1-004 IT 244-1 Introduction to Linux/Unix TuTh 2:00 - 3:15 PM McCormack M1-409 IT 117-1 Intermediate Scripting TuTh 4:00 - 5:15 PM University Hall 2-2310 Home Address: 40 Central Street Somerville, MA 02143 617-821-3936 (9am - 9pm only)
finger
, like mv
, has two functionsfinger
shows every user
currently logged in
$ finger Login Name Tty Idle Login Time Office Office Phone apera Antonio Pera pts/12 7:48 Aug 7 09:53 (73.16.254.131) apera Antonio Pera *pts/15 4:29 Aug 7 15:18 (192.168.105.83) gabrgabr Gabriel Park pts/13 14d Jul 17 09:46 (tmux(29686).%0)5 ...
tofrodos
unix2dos
tofrodos
package provides todos
...fromdos
to go the other wayunix2dos
package uses unix2dos
...dos2unix
to go the other waybzip2
bzip2
is one such utilitybzip2
like this
bzip2 FILENAME
bzip2
compresses the file creating a new file with the extension .bz2bzip2
with the -k
(for keep) optionbzip2
use bunzip2
like this
bunzip2 FILENAME.bz2
bunzip2
decompresses the .bz2 file to recreate the filebzip2
has compressed is unreadablebzcat
bzcat
will print the uncompressed contents of a file to the screenbzcat
does not alter the original, compressed filegzip
- the GNU Compression Utilitygzip
to compress filesbzip2
bzip2
gzip
creates have a .gz extensionzcat
gunzip
tar
- Packaging Files for Transfer or Storagetar
(tape archive) is the Unix utility used for this purposetar
does not compress filestar
is usually used along with a compression programtar
to create a single filetar
to unpack the filestar
with different options ...
tar cvf ARCHIVE_NAME.tar DIRECTORY_NAME
tar -tvf ARCHIVE_FILE
tar -xvf ARCHIVE_FILE
-x
option stands for extractbzip2
is used for compression ...gzip
is used the extensions usually are .tar.gz,
or .tgz ...
$ ls / bin initrd.img proc tmp boot lib root tools courses lib32 run users data lib64 sbin usr dev lost+found selinux var etc media sources vmlinuz groups mnt spool home nobackup srv home.ORIG opt sys
stat
$ stat -f /home | grep Namelen ID: 0 Namelen: 255 Type: autofs
$ ls $ touch Foo foo FOO $ ls foo Foo FOO
gcc
, expects the filenames of source code files to end in .cjavac
, expects Java source files to have .java extensionpwd
(print working directory) command will always tell you your current directoryls
without an argument it will list your current directorycd
(change directory) with no argument
$ cd $ pwd /home/ghoffman
ls
listing ...-a
option