Skip to main content Link Search Menu Expand Document (external link)

đź’» Command-Line Cheat Sheet


The DSMLP servers use Linux. As such, when interacting with them, all of the command-line commands you use should be Linux-specific (which, for the most part, also work on macOS). Many of the key commands you’ll need to know are summarized below.

Basics

CommandDescriptionExample
manShows the manual for a command. This can be helpful for seeing how to run a command or what flags (parameters) a command takes.man cp shows the manual for the cp (copy) command.
pwdDisplays your present working directory.pwd, when run immediately after opening my Terminal, shows /Users/surajrampure.
lslists all files in the current directory.ls
ls -a (also shows all of the hidden files and folders in the current directory (like .gitignore))
mkdirmakes a new directory (folder) with the name you specify.mkdir hello creates a folder in your present working directory named hello. Verify this using ls.
cdchanges your current directory to be the one specified.cd hello enters the directory hello, if it exists in the present working directory. cd by itself always returns you to your “home” directory.
touchCreates an empty file with the specified name.touch ucsd.txt creates a file named ucsd.txt in the present working directory.
catShows the contents of a file.cat hello.txt will display all of hello.txt.
mvmoves a file to a specified location.mv ucsd.txt ../hello.txt moves a file from the present working directory to the parent directory.
Note: In Linux, . represents the current directory and .. represents the parent directory.
cpcopies a file from one location to another.cp hello.txt ../hey.txt makes a copy of the contents in the file hello.txt and saves it in the file hey.txt, stored in the parent directory of the present working directory.
Note: To copy a folder, use the -r flag, which stands for “recursive.”

To verify that you’ve synthesized the above information, answer the following questions:

  • What does cd .. do?
  • What does ls ../hello do?

File Editing

CommandDescriptionExample
vimA command line-based text editor.vim hello.txt opens hello.txt in vim.
emacsAnother command line-based text editor.emacs hello.txt opens hello.txt in emacs.

Servers and Networks

CommandDescriptionExample
sshUsed to access servers (amongst other things).ssh srampure@dsmlp-login.ucsd.edu is how Suraj accesses DSMLP.
scp / sftpAllows you to move files between your local machine and a remote server (essentially ssh + cp).scp dog.txt srampure@dsmlp-login.ucsd.edu:test.txt copies the file dog.txt from your local machine to Suraj’s DSMLP drive (replace with your own username). See DSMLP documentation for more.
wgetDownloads the contents of a webpage.wget https://raw.githubusercontent.com/ericmichael/cooltxt/master/cool.txt creates a new file called cool.txt with the contents of the aforementioned URL.

Other

CommandDescription
clear or ctrl + lClears the Terminal window.
historyShows the commands you’ve entered in the past.
ctrl + rAllows you to search your command history to easily find a command you entered in the past.
screenAllows you to run tasks in the background. See here for more details.
gitSee usage reference here.
grepHelps you quickly search text (both individual documents and folders). The general pattern is grep -inr <keyword> <file_path>.
For example, grep -inr dog hello.txt will display all lines in which 'dog' occurred in hello.txt.
findHelps you quickly find a file using regex. For example, find <path> -iname <regex>.
htopShows you all of the processes currently running on your server and the amount of resources (e.g. CPU and memory) that you’re using.

(source)

If you have any feedback for this page, let us know!