Child pages
  • Question 1 - Basic Unix Commands
Skip to end of metadata
Go to start of metadata


  1. ls --- Lists all files in your current directory.
    • ls -l: lists your files in your current directory showing protection codes, date of creation (or last modification), and size.
    • ls -a: lists all files, including the ones whose filenames begin with a dot, e.g. .login.
    • ls *.txt: lists all files in your current directory that end with the characters '.txt' (e.g. myexample1.txt).
    • ls -F: lists files in your current directory, putting a slash (/) after those that are directories and an asterisk (*) after those that are executables.
  2. mkdir --- Makes a new subdirectory within (or below) the current directory.
    • mkdir Classes: creates a new subdirectory named Classes within the current working directory.
  3. mv --- Renames or moves the specified file.
    • mv Class1.txt Schedule1.txt: renames file Class1 as Schedule1. This command can also be used to moves a file into a different directory.
  4. pwd --- Displays the full pathname of the current working subdirectory.
  5. cd --- Changes directory. You basically 'go' to another directory, and you will see the files in that directory when you do 'ls'.
    • cd: You always start out in your 'home directory', and you can get back there by typing 'cd' without arguments.
    • cd ABC: Move to directory ABC.
    • cd ..: Moves you one level up from your current position. Specifying pathnames will avoid moving backwards (or forward) step by step.
  6. cp --- Copies a file.
    • cp Class1.cpp ABC.cpp: copies file Class1.cpp as ABC.cpp.
  7. rm --- Removes a file. Once deleted this file can not be retrieved again.
    • rm -i Class1.txt Class2.cpp: deletes both files but asks for confirmation before deleting anything (it is advisable to include this as default by making an alias in your .cshrc file).
  8. rmdir --- Removes a subdirectory which can not contain any file.
    • rmdir ABC: removes the empty subdirectory called ABC.
  9. more --- Shows the first part of a file fitting as much as possible on one screen. Hit the space bar to see more or q to quit.
    • more Class1.txt
  10. emacs --- Opens an editor (called emacs) that lets you create and edit a file.
  11. diff --- Compares files, and shows where they differ.
    • diff ABC DEF: compares files ABC and DEF and displays any lines in ABC or DEF that differ from each other.
  12. wc --- Tells you how many lines, words, and characters there are in a file.
    • wc ABC
  13. chmod --- Lets you change the read, write, and execute permissions on your files. By default only you can look at your files and change them.
    • chmod o+r Class1.c: makes the file readable for everyone
    • chmod o-r Class1.c: makes it unreadable for others again.
  14. grep --- Looks for a specified string in the listed files.
    • string filename(s): This can be useful a lot of purposes, e.g. finding the right file among many, figuring out which is the right version of something, and even doing serious corpus work. grep comes in several varieties (grep, egrep, and fgrep) and has a lot of very flexible options.
File Compression
  1. gzip --- Compresses files, so that they take up much less space. Usually text files compress to about half their original size, but compression depends on the size of the file and the nature of the contents.
    • gzip ABC.c: Produces a file ABC.c.gz — with 'gz' appended to the original filename; it usually gives the highest compression rates.
  2. gunzip --- Decompresses files compressed by gzip.
    • gunzip ABC.c.gz: Decompresses file ABC.c.gz previously compressed by gzip.


  1. cal --- Shows a calendar of the current month.
    • cal 10 1995: provides calendar for October 95.
  2. date --- Displays the current date and time.
  3. man --- Helps to get information on a Unix command by looking up its correspondent page in the online manual for that command.
    • man CC: shows the pages of the Unix manual referring to the C++ compiler (CC) on the screen.
  4. w --- Tells you who's logged in, and what they're doing.
  5. who --- Lists the users currently logged in to a given machined and where they're coming from.
  6. whoami --- Returns current username.
  7. finger --- Gives information about a specific user, e.g. when they last read their mail and whether they're logged in.
    • finger user1: provides information about user1.
  8. last user1 --- Tells you when the user last logged on and off and from where. Without any options, last will give you a list of everyone's logins.
  9. hostname --- Prints the current hostname.
  10. passwd --- Lets you change your password, which you should do regularly (at least once a year). and/or look at help password.
  11. ps --- Lists your processes. Contains lots of information about them, including the process ID, which you need if you have to kill a process.
    • ps -u yourusername
  12. kill --- Kills (ends) the processes with the ID provided. Works only for your own processes.
    • kill Process_ID
  13. lpr --- Prints files.
    • lpr -Pxxx ABC DEF: prints out the contents of the file ABC followed by the contents of the file DEF on printer xxx.
  14. enscript --- Prints a file with filename, date, and page number.
    • enscript -Pxxx -2rG ABC: prints the contests of dile ABC on the printer named xxx with two columns per page (-2), rotated 90 degrees (-r) so that it appears in a landscape format, with a gaudy heading (-G) as a shaded bar across the top that provides the filename (ABC), the creation date of that file, and the page number.
  15. quota --- Shows what your disk quota is (i.e. how much space you have to store files), how much you're actually using, and, in case you've exceeded your quota, how much time you have left to sort them out.
  16. setenv --- Changes environmental settings.
    • setenv PRINTER print123: makes print123 the default printer for any lpr or enscript commands.
  17. time --- Checks the execution time of a given command.
    • time anycommand: executes anycommand and returns the user, system, and total time taken for the execution.

Connecting to the outside world

  1. ssh --- Connects to a secure shell.
  2. telnet --- Allows connection to a remote host. Use rlogin whenever possible.
    • telnet hostname
  3. ftp --- Lets you download files from a remote host which is set up as an ftp-server. This is a common method for exchanging academic papers and drafts.
    • ftp hostname
  • No labels