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 UsersI have posted Homework 4 here.
As usual, it will be due next Sunday at 11:59 PM.
The is the first homework assignment that will require you to write a script.
Your script must meet certain requirements that I mentioned in the last class.
Let's review the requirements for homework scripts.
I have posted the answers to Quiz 1 here.
ssh window open ...nano or a Unix text editor ...echo statement
echo Step 1
cat at the beginning of a
pipeline ...
cat to create input ...grep, sort, head or tailcat in a pipe with these commands ...catcat 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 Win red_sox.txt | grep vs
grep Win red_sox.txt | grep vs red_sox.txt # WRONG
grep ...grepuniq - Eliminate Duplicate Linesuniq prints the lines of a file to the screen ...uniq is often used with sort-i option makes uniq ignore 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 readtsoro@vm74:~/it244/work$
file - 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
$ 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 sortdate - 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 provideswhich - Finding a Program Filewhich gives the location of an executable fileless is located ...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 whichwhereis searches these locationswhereis on the tar utility ...which returned
$ whereis tar tar: /bin/tar /usr/include/tar.h /usr/share/man/man1/tar.1.gz
man used to provide information about tarlocate - Search for Any Filewhich and whereis only work on programslocate can be used to find any filelocatelocate 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 itselfupdatedbupdatedb 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 rickm pts/0 2017-12-07 03:05 (192.168.105.41) apera pts/1 2018-01-13 04:54 (73.16.254.131) tsoro pts/2 2018-01-14 15:23 (24.62.10.159) apera pts/5 2018-01-11 20:04 (192.168.107.83) jkamby pts/8 2018-01-11 15:21 (66.30.11.52) onic pts/9 2018-01-11 13:15 (158.121.18.145)
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 tsoro pts/2 2018-01-14 15:23 (24.62.10.159)
finger - Get information on Usersfinger provides information about a user account
Login: tsoro Name: Torna O. Soro Directory: /home/tsoro Shell: /bin/bash On since Sun Jan 14 15:23 (EST) on pts/2 from 24.62.10.159 7 seconds idle Mail forwarded to tsoros@gmail.com No mail. No Plan.
$ finger ghoffman Login: ghoffman Name: Glenn Hoffman Directory: /home/ghoffman Shell: /bin/bash On since Thu Sep 24 11:43 (EDT) on pts/5 from 158.121.249.7 5 seconds idle Mail forwarded to glennhoffman@mac.com New mail received Fri Sep 18 14:00 2015 (EDT) Unread since Fri Sep 18 07:43 2015 (EDT) Plan: Office: Science 3-92A (Pterosaur poster on door) Office Hours: Tuesday & Thursday, 12:30 - 1:30 PM and 5:30 - 6:30 PM On Campus: Wednesday 1 - 6PM Appointment needed on Wednesday Classes: IT 244-01 Introduction to Linux/Unix TuTh 2:00 - 3:15 PM Science S3-143 (IT Lab) IT 244-02 Introduction to Linux/Unix TuTh 4:00 - 5:15 PM Science S3-028 (Web Lab) IT 341_02 Introduction to System Administration TuTh 7:00 - 8:15 PM Science S3-143 (IT Lab) Home Address: 40 Central Street 617-821-3936 (home; 9am - 9pm only) Somerville, MA 02143
finger, like mv, has two functionsfinger shows ever user currently logged in
$ finger Login Name Tty Idle Login Time Office Office Phone eb Ethan Bolker pts/4 3:35 Sep 22 19:19 (pool-108-26-203-122.bstnma.fios.verizon.net) ghoffman Glenn Hoffman pts/5 Sep 24 11:43 (158.121.249.7) root root *tty1 52d Mar 11 2015
finger
$ finger hoffman
Login: ghoffman Name: Glenn Hoffman
Directory: /home/ghoffman Shell: /bin/bash
On since Thu Sep 24 11:43 (EDT) on pts/5 from 158.121.249.7
2 seconds idle
Mail forwarded to glennhoffman@mac.com
New mail received Fri Sep 18 14:00 2015 (EDT)
Unread since Fri Sep 18 07:43 2015 (EDT)
Plan:
Office: Science 3-92A (Pterosaur poster on door)
Office Hours: Tuesday & Thursday, 12:30 - 1:30 PM and 5:30 - 6:30 PM
On Campus: Wednesday 1 - 6PM Appointment needed on Wednesday
Classes: IT 244-01 Introduction to Linux/Unix TuTh 2:00 - 3:15 PM Science S3-143 (IT Lab)
IT 244-02 Introduction to Linux/Unix TuTh 4:00 - 5:15 PM Science S3-028 (Web Lab)
IT 341_02 Introduction to System Administration TuTh 7:00 - 8:15 PM Science S3-143 (IT Lab)
Home Address: 40 Central Street 617-821-3936 (home; 9am - 9pm only)
Somerville, MA 02143
Login: ghoffmn Name: Glenn Legacy Hoffman
Directory: /home/ghoffmn Shell: /bin/bash
Last login Mon Jul 13 13:14 (EDT) on pts/5 from dsl092-066-161.bos1.dsl.speakeasy.net
Mail forwarded to glennhoffman@mac.com
Mail last read Thu May 28 18:30 2015 (EDT)
Plan:
Office: McCormack M-3-607 Fall 2014
Office Hours: Tuesday & Thursday, 10:00 - 12:00 PM and by appointment
Classes:
IT 341-2 Introduction to System Administration TuTh 12:30-1:45 S3-148 (IT Lab)
IT 244-1 Introduction to Linux/Unix TuTh 2:00-3:15 S3-028 (Web Lab)
IT 244-3 Introduction to Linux/Unix TuTh 4:00-5:15 S3-148 (IT Lab)
IT 244-2 Introduction to Linux/Unix TuTh 5:30-6:45 S3-028 (Web Lab)
Home Address: 40 Central Street 617-821-3936 (home; 9am - 9pm only)
Somerville, MA 02143
Login: it244gh Name: Glenn Hoffman Dummy
Directory: /home/it244gh Shell: /users/nologin
Never logged in.
Mail forwarded to glennhoffman@mac.com
No mail.
Plan:
This account is a test account for Glenn Hoffman teaching it244
$ 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
cat or less on a directory or a printerstat
$ stat -f /home | grep Namelen ID: 0 Namelen: 255 Type: autofs
ls on a directory that has a filename with a space in it ..$ touch 'foo bar' $ ls foo bar
$ ls -l foo\ bar -rw-r--r-- 1 it244gh it244-2G 0 2011-09-24 14:34 foo bar
$ touch foo_bar $ ls foo_bar
$ ls $ touch Foo foo FOO $ ls foo Foo FOO
gcc, expects the filenames of source code files ...javac, expects Java source files ...pwd (print working directory) commandls without an argument ...cd (change directory) with no argument
$ cd $ pwd /home/tsoro
ls listing ...ls with the -a option