# Linux Command Line

# Advanced

For a more advanced guide on Linux and more in depth commands, visit Linux Guide.

# Help

  • Manual/Help Page(s)
    • man [cli command]
      • Eg. man ls

# Files and Directories

  • List files in current directory
    • ls
    • ls -als (long form)
      • Eg. ls -als *.cpp
  • Move/rename files
    • mv [old name] [new name]
      • Eg. mv assignment1.ccp assignment.cpp (rename)
      • Eg. mv assignment1.cpp ~/Documents/CS135/ (move)
  • Copy files
    • cp [original file] [new file name]
      • Eg. cp assignment1.cpp assignment1_copy.cpp
  • Delete files
    • There is no way to recover deleted files
    • rm [filesname]
      • Eg. rm assignment1.cpp
    • rm -r [directory] (recurse and delete all files in directory as well as directory)
      • Eg. rm -rf ~/Documents/CS135
      • rmdir [directory] can be used if directory is empty
  • Print current working directory
    • pwd
  • Make directory
    • mkdir [directory]
      • Eg. mkdir CS135
  • Change directory
    • cd [directory name]
      • Eg. cd CS135
      • Eg. cd ~/Documents/CS135 (full path if directory is not below current path)
      • Eg. cd (Return to home directory. Equivalent to cd ~)
      • Eg. cd .. (Go up one level in the directory tree)
  • Print file contents
    • cat [filename]
      • Eg. cat assignment1.cpp

# Process Control

  • Terminate/suspend current foreground process
    • Ctrl + C on keyboard to terminate
    • Ctrl + Z to suspend
  • Find a process
    • ps
      • Eg. ps -ef | grep [username] (Print processes belong to username)
  • Logout
    • Ctrl + d
    • logout

# Printing

  • Printing in Linux
    • Printing to the default printer: lpr [filename]
    • Printing to a different printer: lpr -P[printername] filename
    • Checking your default printer and listing the current print jobs: lpq
      • The first line of the output of lpq shows your default printer

Note: You can print when logged on remotely from any location so long as you are logged into bobby, cardiac, or java.

  • Printing in Windows

    • All print menus should work. To check your default printer, go to Start -> Printers and Faxes, and see which printer has a check mark.
  • Printing Quota

# Sending Email

  • First Log into a UNLV CS Server such as sally.cs.unlv.edu. Email from the terminal (command line / shell prompt) can be sent as follows.

  • mail user@domain.edu

    • This will prompt for a subject and then you can type the body of the mail.
    • Hit ctrl-d to send the mail -- EOT (end of transmission) will be displayed.
  • mail user@domain.edu < file.cpp

    • Sends file.cpp in the body of the email with no subject line
  • mail user@domain.edu,user2@domain.edu < file.cpp

    • Same as the above, but sends file.cpp to two recipients
  • mail -s "Subject line here" user@domain.edu < file.cpp

    • Sends file.cpp to a recipient with a subject line

Note: The 'from' address on emails sent will be from your username @unlv.nevada.edu; replies to that email will be sent to your RebelMail account.

For more details on using Linux mail utility, see this page (opens new window).