This page is from the old wiki. It’s a guide for becoming more familiar with the command line. These are some basic GNU/Linux terminal commands that are useful to know as a minimum. Feel free to edit this post as a wiki page – just click the “edit” button.
Most commands come with documentation in the form of “man[ual] pages”. To read the man page for a command use the
Example: to read the documentation for the
ls command, type
man ls in a terminal. You can also search Google for information on any command.
List of Useful Commands
ls– list directory contents. Also
ls -R, and
cd– change directory
cp– copy files
mv– move a file or directory. Also for renaming things
mkdir– make a directory
rm– remove a file. Also
rm -rf, but very dangerous. See this story for a warning on how dangerous it can be.
rmdir— remove a directory
touch– create a new empty file
pushd– move to another directory with a bookmark (actually a stack of directories you’ve jumped from, so you can use it multiple times)
popd– jump back to the place where you pushd’d from
pwd– show current location
clear– clear the terminal. Also ctrl-l
less– display output with pagination
vimtutorand see the [[Vim]] page.
nano– simple console editor
cat– display a file and/or concatenate it
top– show processes. If you like that, install
man– read the built-in documentation
locate– find files. E.g.,
sudo updatedb; locate *.desktop
find– find files. E.g.,
find / -name '*.desktop'
grep– search files and directories
tree -d >> outputfile.txt. You may need to install it first.
gzip– manage archives
wc– count things: lines, bytes, characters, words, etc. Example:
wc -l filename.txtwill count the lines in a file.
tee– redirect the output to a file and the screen at the same time. E.g.,
ls -1 *.py | wc -l | tee count.txtwhich counts the number of Python files in your directory, writes it to the screen, and saves it to a file.
apropos– can’t remember a command? Use this to find commands about a keyword, like:
- tab completion
- ctrl-r – reverse search
- keyboard shortcuts: ctrl-u, ctrl-k, ctrl-a, ctrl-e, alt-f, alt-v, ctrl-d, alt-d (from Emacs)
For managing remote servers: ssh, scp, and rsync
Some of these may need to be installed.
sort– sorts items
uniq– gets only unique items
mc– Midnight Commander file browser
fold– wrap lines to a specified width
jq– tools for JSON
curl– do stuff with URLs
wget– download pages and sites
npm install -g sql2csv)
pip install csvkit)
git cloneit and add to path)
- ImageMagick – process and view images, e.g.,
convert --resize 200x200 giant_hubble_photo.jpg hubble_photo_thumb.jpg
rename– bulk rename files with regular expressions. Example: rename all files with the extension
rename -v 's/\.GIF$/\.gif/' *.GIF
lynx– a browser in your terminal.
You will occasionally come across these:
sed– stream editor for filtering and transforming text
awk– pattern scanning and processing language
- Perl one line scripts
See additional tools that you might want to investigate:
How to use the terminal for everything:
tig can be used as an alternative to
ranger is a file browser.
See this post for useful keyboard shortcuts:
See also 7 command line tools for data science.
See also GNU Coreutils Manual.
There are additional posts here: #command-line.