A few useful Unix Commands
Helpful Unix Commands
- who
"who" - those currently using the system
- users
"users" - account names of people using the system
- whoami
whoami (no spaces) - this commands lists the account name associated with the current login
- who am i
who am i (with spaces) host name and domain name (name of computer and internet address
of computer), account name, communication line, and date
- date
gives current date
- time
gives execution time of last command
- ls
list files (-s for size in K, -a for all files, -F for file types, -m gives a
comma separated list, ls -l gives a full listing, and shows permissions)
- env
To view your environment - the user environment is a collection of specially named
variables that have specific values
- rm
to delete a file:
syntax: rm name_of_file
- rm -i
to delete a file with confirmation
- cd
to move into a directory:
syntax: cd name_of_directory
- mkdir
to make a new directory:
syntax: mkdir name_of_new_directory
- cd ..
to move back a directory level:
syntax: cd ..
After you have done the above command, check to see where you are by entering
pwd
- mv
to rename a file:
syntax: mv old_filename new_filename
- pwd
pwd tells you where you are. It tells you the names of all the directories
above you.
- csh
lance un nouveau shell
C-shell has the prompt %, Bourne-Shell uses $.
Files
- cp
to copy a file into the next directory:
syntax: cp name_of_file name_of_directory
- cp -i
copy with confirmation
- cmp
compares two tex files
- diff
compares two directories
- head
print the first lines on screen
- tail
print the last lines on screen
- nl
list a file with numbered lines
- sort
sort lines by alphabatic order on screen
- sort -r
sort in reverse order
- sort -n
sort on first numerical word
- sort -o
sort and write in another file
- sort -f
sort in neglecting case
- sort -b
sort in neglecting initial spaces
- cat nam1 nam2 > nam3
concatenates 2 files in a third one
- cut -b l1 l2 file
extracts columns from l1 to l2 from file on screen
- cut -b l1 l2 filin > filout
extracts columns from l1 to l2 from filin to filout
- chmod ugo+wrx
modifies protections (user, group, other; write, read, execute)
- chown
changes owner of files
Compression
- compress
compress file
- uncompress
uncompress file
- gzip
gnu-zip compress file
- gunzip
gnu-zip uncompress file
- uuencode
code file from binary to ascii
useful to send a compressed file(binary) on mail
- uudecode
decode file
Directories
- quota -v
informs you of space available on disk for you
- du -s
gives sizes of directories at this level, in blocks=512Ko
Paths
- cd
returns in your home directory
- .
is the current directory
- ..
is the directory above
- cp -r /rep1/rep2/* .
copies all a hierarchy in the current directory
- dircmp
compares two directories
- find orig -name < file > -print
search a file in the tree below orig, and print the path
- find /rep1/rep2 -atime -60 -name "*.ps" -print
search all .ps files in the tree below /rep1/rep2, created less than 60 days ago, and print them
- grep " nam " *
search for nam in all files of present directory
- grep copying help
This searches the file help for the string copying and displays each
line on your terminal
- ls -l | grep '^d........x'
To use the output of another command as input to the grep command:
This lists all the directories in the current directory for which other
users have execute permission. The expression is quoted to prevent the
shell interpreting the ^ metacharacter
- grep Smith /etc/passwd > smurffs
To redirect the results of a search to a file, use the ">" command:
This searches the passwd file for each occurrence of the name Smith and
places the results of this search in the file smurffs
Linux