Advertising

Welcome to SparkyLinux forums
Zapraszamy również na polsko-języczne Forum Linuxiarze.pl

Author Topic: Linux Command Line Cheatsheet  (Read 3713 times)

Offline way12go

  • Sr. Member
  • ****
  • Posts: 480
  • Karma: 0
  • Life is a unique pattern.
Linux Command Line Cheatsheet
« on: November 08, 2014, 05:17:28 am »
Linux Command Line Cheatsheet

File Commands

Spoiler (click here to view)
ls - List the content of the current directory

ls -R - List the subdirectories recursively

ls -a - List all the content, including hidden files

ls -l - List the content and its information

pwd - Output the current directory that you are in

cd folder1 – Change the working directory to folder1

cd - Return to the $Home directory

cd .. - Go up a directory

cd - - Return to the previous directory

cp source destination – Copy source to destination

cp -r source destination – Copy a folder recursively from source to destination

mv source destination - Move (or rename) a file from source to destination

rm file1 - Remove file1

rm -f file1 - Remove file1 without prompt

rm -r folder - Remove a folder and its content recursively

mkdir foldername – Create a new folder foldername

rmdir foldername – Remove an empty folder

file file1 – Show the file type of file1

cat file1 file2 – Concatenate file1 to file 2

cat > file1 – Concatenate standard input to file1

less file1 - View and paginate file1

head file1 - Show first 10 lines of file1

tail file1 - Show last 10 lines of file1

chmod 777 file - Change file permission of file to 777

chown user:group file - Change ownership of file to user and group group

ln -s source destination – Create a symbolic link from source to destination

File Encryption and Compression

Spoiler (click here to view)
gpg -c file - Encrypt file

gpg file.gpg - Decrypt file.gpg

tar -cf archive.tar foo bar - Create archive.tar from files foo and bar

tar -xf archive.tar - Extract all files from archive.tar

tar -czf archive.tar.gz foo bar - Create archive.tar.gz from files foo and bar, with Gzip compression

tar -xzf archive.tar.gz - Extract a tar using Gzip

tar -cjf archive.tar.bz2 foo bar - Create archive.tar.bz2 from files foo and bar, using Bzip2 compression.

tar -xjf archive.tar.bz2 – Extract a tar using Bzip2

gzip file1 – Compress file1 and rename it to file1.gz

gzip -d file1.gz – Decompress file1.gz

SSH

Spoiler (click here to view)
ssh $USER@$HOST – Connect to $Host as $USER

ssh $USER@$HOST command - Run command on $HOST as $USER

ssh $USER@$HOST -p 1234 – Connect to $HOST as $USER on port 1234

scp file1 $USER@$HOST:file1 – Secure copy file1 from local machine to file1 at remote $HOST

scp $USER@$HOST:file1 file1– Secure copy file1 from remote $HOST to file1 at local machine

scp -r foo $USER@$HOST:/bar – Secure copy the folder foo from local machine to the folder bar at remote $HOST
Package Installation

Spoiler (click here to view)
dpkg -i package.deb - Install a deb package

rpm -Uvh package.rpm – Install a rpm package

System Commands

Spoiler (click here to view)
uname -a - Show system and kernel

head -n1 /etc/issue - Show distribution

mount - Show mounted filesystems

date - Show system date

uptime - Show system uptime

whoami - Show your username

w - Display who is online

man command - Show manual for command

mount -o loop cdrom.iso /mnt/dir - Mount cdrom.iso at /mnt/dir

cat /proc/partitions - Show all partitions registered on the system

grep MemTotal /proc/meminfo - Show RAM total seen by the system

grep "model name" /proc/cpuinfo - Show CPU(s) info

lspci -tv - Show PCI info

lsusb -tv - Show USB info

!! - Repeat the last command

exit – Log out of current session

File Searching Commands

Spoiler (click here to view)
grep pattern files - Search for pattern in files

grep -i - Case insensitive search

grep -r - Recursive search

grep -v - Inverted search

grep -o - Show matched part of file only

locate file1 - Find file1

whereis command - Find binary/source /manual for command

which app – Locate a command for the app

look string file1 - Display any lines in file1 which contain string as a prefix.

find /dir/ -user name - Find files owned by name in dir

find /dir/ -mmin num - Find files modifed less than num minutes ago in dir

find /dir/ -name name* - Find files starting with name in dir

Process Management

Spoiler (click here to view)
ps - Show snapshot of processes

top - Show real time processes

kill pid - Kill process with id pid

pkill name - Kill process with name name

killall name - Kill all processes with names beginning name

Keyboard Shortcuts

Spoiler (click here to view)
Ctrl + Shift + c - Copy a highlighted text

Ctrl + Shift + v – Paste a copied text

Ctrl + z - Sleep program

Ctrl + c – Stop current command

Ctrl + r – Start a search

Ctrl + u – Cut from start of line

Ctrl + k – Cut to end of line

Ctrl + a – Go to start of line

Ctrl + e – Go to end of line

Disk Space

Spoiler (click here to view)
df -h - Show free space on mounted filesystems

df -i - Show free inodes on mounted filesystems

du -h folder – Show file usage of each folder in folder

du -sh folder – Show the total file size of folder

fdisk -l - Show disks partitions sizes and types (run as root)

free – Show memory and swap usage
« Last Edit: November 29, 2014, 07:08:07 am by way12go »
Life is a unique pattern.