Here are some basic Linux commands to get you up and running, or a quick cheat sheet. Great for when working on a Raspberry Pi or any other single board computers which use Linux commands such as Beagleboard / Beaglebone, Asus Tinker Board and many others.
Files and Navigating
Command | Description |
---|---|
ls | Directory listing (list all files/folders on a current directory) |
ls -l | Directory listing, with the file details in a formatted way, easier to read |
ls -la | Directory listing the same as ls -l but this will also display hidden files |
cd dir | Change directory to dir (dir will be directory name) |
cd .. | Change to the parent directory |
cd ../dir | Change to dir in the parent directory (dir is replaced with a specific directory) |
cd | Change to the home directory |
pwd | Show current directory |
mkdir dir | Create a directory dir (replace dir with your chosen name) |
rm file | Delete a file |
rm -f dir | Force remove a file |
rm -r dir | Delete directory dir |
rm -rf dir | Remove directory dir |
rm -rf / | If run by a superuser, will delete every file on the system (DO NOT DO THIS) |
cp file1 file2 | copy file1 to file2 |
mv file1 file2 | Rename file1 to file2 |
mv file1 dir/file2 | Move file1 to dir as file2 |
touch file | Create or update file |
cat file | Output contents of a file |
cat > file | Write standard input into a file |
cat >> file | Append standard input into a file |
tail -f file | Output contents of a file as it grows |
Networking
Command | Description |
---|---|
ping host | Ping host |
whois domain | Get whois for a domain |
dig domain | Get DNS for domain |
dig -x host | Reserve lookup host |
wget file | Download file |
wget -c file | Continue a stopped download |
wget -r url | Recursively download files from a URL |
curl url | Outputs the webpage from a URL |
curl -o hello.html URL | Writes the page to hello.html |
ssh user@host | Connect to host as user |
ssh -p port user@host | Connect using port |
ssh -D user@host | Connect & use bind port |
Processes
Command | Description |
---|---|
ps | Display currently active processes |
ps aux | Detailed outputs |
kill pid | Kill process with process id (pid) |
killall proc | Kill all processes named proc |
System Information
Command | Description |
---|---|
date | Show current date / time |
uptime | Show uptime |
whoami | Currently logged in user |
w | Display who is online |
cat /proc/cpuinfo | Displays CPU information |
cat /proc/meminfo | Displays memory information |
free | Show memory and swap usage |
du | Show directory space usage |
du -sh | Displays readable sizes in GB |
df | Show disk usage |
uname | Add "-a" after the command to show all kernal information, for more specific information the following switches can be used "-m, -r, -v, -n" |
sudo -lshw | Calls the lshw tool which gathers vast information about the computer’s hardware such as CPU, disks, memory, USB controllers etc |
lscpu | Display CPU information |
lsusb | Displays USB controllers information |
lspci | Displays PCI devices information |
Compressing
Command | Description | Switches | Switch Description |
---|---|---|---|
tar cf file.tar files | Tar files into file.tar | ||
tar xf file.tar | Untar into a current directory | ||
tar tf file.tar | Show contents of archive | c | Create an archive |
t | Table of contents | ||
x | Extract | ||
z | Use zip / gzip | ||
f | Specify a filename | ||
j | Bzip2 compression | ||
w | Ask for confirmation | ||
k | Do not overwrite | ||
T | Files from a file | ||
v | Verbose |
Permissions
Command | Description | Switches | Switch Description |
---|---|---|---|
chmod octal file | Change permissions of a file | 4 | Read (r) |
2 | Write (w) | ||
1 | Execute (x) | ||
chmod 777 | rwx for everyone | ||
chmod 755 | rw for the owner, rx for group world |
Calculating the number for permissions in chmod is done by adding the numbers for the permission you want granted. For example if you wanted to give read, write and execute permissions, you would add 4+2+1 = 7 (refer to the table above for which numbers relate to which permission). The 3 numbers in the chmod permission is broken up into the first number being the owners permissions, followed by the groups permissions and finally the publics permissions.Â
Other Useful Commands
Command | Description |
---|---|
grep pattern files | Search in files for a pattern |
grep -r pattern dir | Search for pattern recursively in dir |
locate file | Find all instances of a file |
whereis app | Show possible locations of app |
man command | Show manual page for a command |