CS155 Commands4
$ date Thu Nov 21 09:47:27 MST 2024 $ cal November 2024 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 $ cal 11 1957 November 1957 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
date
- Display the current date and time
cal
- display a simple calendar
-3
- Display previous, current, and next month
-y
- Display a calendar for the year
uptime
- information on system load, number of users, and uptime
who
- list of users currently logged in
w
- combination of uptime and who
11:32:19 up 9 days, 17:43, 3 users, load average: 0.00, 0.00, 0.00 USER TTY LOGIN@ IDLE JCPU PCPU WHAT cs155 pts/0 11:32 0.00s 0.08s 0.00s w applin pts/1 11:32 14.00s 0.08s 0.08s -bash
which
- give the full path of an executable
% which cat /bin/cat
whereis
- search all common executable directories for
binaries (executable files), man pages, source files.
% whereis date date: /usr/bin/date /usr/share/man/man1p/date.1p.gz /usr/share/man/man1/date.1.gz
find
– searches the file system for a file or files based on name,
size, when changed, etc.
find
path expression
find
searches recursively from path down looking for files
that match expression.
find -name
pattern : search for files with name matching pattern.
Pattern uses wildcard symbols.
% find ~/pub/ -name '*.t??' /s/bach/a/class/cs155/pub/dwarfs.txt /s/bach/a/class/cs155/pub/hw3.tgz /s/bach/a/class/cs155/pub/domains.txt
find . -name html
html
find . -name "*html"
html
-user
username : file is owned by username
-amin -
n : file access up to n minutes ago
-mtime -
n : file was last modified up to n days ago
% find ~/pub/ -user cs155 -name 'jack.*' /s/bach/a/class/cs155/pub/hw2Files/jack.info /s/bach/a/class/cs155/pub/hw2Files/jack.log /s/bach/a/class/cs155/pub/hw2Files/jack.jpg /s/bach/a/class/cs155/pub/hw2Files/jack.grades
find
to perform on each file it finds.
-delete
: delete found files (life in the fast lane)
-ls
: give full listing of files
-exec
command : run command on files
% find . -mtime -1 -ls 8798609 12 drwx--x--x 84 applin fac 12288 Jan 1 16:43 . 8799248 4 -r-------- 1 applin fac 395 Jan 1 17:01 ./monster 1246232 4 drwxrwxr-x 3 applin fac 4096 Jan 1 16:43 ./public_html/wiki/cookbook
find . -name "*.bak" -exec mv {} old \;
Search for a string in a selection of files (executing grep):
find . -exec grep "Boese" '{}' \; -print
-exec
action can be very handy.
-exec
is considered part of the command to
execute until a ;
is encountered. The ;
must be escaped by
using \
because it is a special character in the shell.
{}
are replaced by the full path to the found file.
uname
– print system information
-a
: print all information
% uname -a Linux beethoven 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64 x86_64 x86_64 GNU/Linux
su
- switch user (login in as different user)
whoami
– get current user name
% whoami cs155
touch
– change access and modification times of files
bc
– Basic Calculator
ispell
– spell check a file
ping
– check whether another computer is alive
% ping -c1 denver PING denver.cs.colostate.edu (129.82.44.141) 56(84) bytes of data. 64 bytes from denver.cs.colostate.edu (129.82.44.141): icmp_seq=1 ttl=64 time=0.396 ms --- denver.cs.colostate.edu ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.396/0.396/0.396/0.000 ms
kazoo
or kazoo.cs.colostate.edu
.
tuba
.
A list of CS department printers: https://www.cs.colostate.edu/~info/printers
lpr
– send file to printer without formatting
-Pprinter
: sent to printer
lpr -Ptuba my_file
lpq
– list the printer queue
lpq -Ptuba
lprm
– remove print job
lprm -Ptuba 452
% lpr -Ptuba my_file % lpr -Ptuba my_file2 % lpq -Ptuba tuba is ready and printing Rank Owner Job File(s) Total Size active applin 1016 my_file 1944576 bytes 1st xhua 1021 (stdin) 12432 bytes 2nd applin 1028 my_file2 134144 bytes % lprm -Ptuba 1028 % lpq -Ptuba tuba is ready and printing Rank Owner Job File(s) Total Size active xhua 1021 (stdin) 12432 bytes