Skip to main content

Shell commands

View manual: man​

  • Section 0 - Everything
  • Section 1 - User Commands
  • Section 2 - System Calls (functions provided by the kernel)
  • Section 3 - Subroutines (Library Calls)
  • Section 4 - Special Files (like device files in /dev directory
  • Section 5 - File Formats and Conversions e.g. /etc/passwd
  • Section 6 - Games for Linux, self-explanatory
  • Section 7 - Miscellaneous, e.g.Macro Packages and Conventions
  • Section 8 - System Management Commands
  • Section 9 - Kernel Routines
  • Section n - New documentation, that may be moved to a more appropriate section.
  • Section l - Local documentation referring to this particular system

See also man man

Show file structure: tree​

Copy files: cp​

If you need to copy files from your local computer to the computer you are accessing remotely, use the scp command:

scp /localdirectory/example1.txt <username>@<remote>:<path>

will copy example1.txt to the specified <path> on the remote computer. You can leave <path> blank to copy to the root folder of the remote computer.

scp <username>@<remote>:/home/example1.txt ./

will move example1.txt from the home directory on the remote computer to the current directory on the local computer.

Move/rename files: mv​

Add alias: alias​

Speeds up daily routine

alias [key]=[text]
# Do not include the flag -- or -

# in .bash_profile
alias runui="cd /c/workspace/;yarn dev"

Add path: export​

export PATH=\$PATH:[/usr/sbin]

Install apps: apt​

# update all apps
sudo apt update && sudo apt upgrade

# install app XXX
apt install [XXX]

# Variations to skip confirmation
sudo apt install --assume-yes

Change permission: chmod​

# Grant user execution permission of file:
chmod u+x file

# Grant everyone all permissions
chmod 777

allows multiple filenames to be associated with the same file

Stream Editor: sed​

Most common for text replacement

View processes: ps​

ps -ef
# Flag -e means all processes
# Flag -f means show process details and flags

Concatenate: cat​

conCATenate

Search: grep​

Use --color flag to show matches in color!

Show logged on users: who​

Divide a file: cut​

Report or omit repeated lines: uniq​

Word count: wc​

Delete folder: rm -rf​

Create new file: touch​

Displaying data: od​

displaying ("dumping") data in various human-readable output formats: Od -vtu1 filename The name is an acronym for "octal dump" since it defaults to printing in the octal data format

Translate: tr​

# Replace line endings with comma
Tr '\r' ','

Extract: tar​

tar -xf [file]

Shutdown/restart: shutdown​

sudo shutdown -r

# force shutdown right away
sudo shutdown --reboot now

Check connection: ping​

Download from remote: wget​

# wget's major advantage over curl is it downloads recursively
wget [url]

## Transfer data: curl
curl -http2 [url]
curl [url]

SSH into remote: ssh​

ssh [email protected] -p 7777

You'll be prompted to accept the host’s key the first time you connect