ssh user@host # Connect to host as userssh -p port user@host # Connect to host using specific porttelnet host # Connect to the system using telnet port
Directory Traverse
1234
cd# Go to $HOME directorycd ~ # Alias to: Go to $HOME directorycd .. # To go up one level of the directory treecd /var # Change to /var directory
File Transfer
scp
123
scp file.ext host:/path #Secure copy "file.ext" to remote host "/path" folderscp user@host:/path/*.txt /local_path # Copy *.txt files from remote host to current system "local_path" folderscp -r user@host:/www /www/tmp # Copy all files and folders recursively from remote server to the current system /www/tmp folder
rsync
12
rsync -a /home/docs /backup/ # Synchronize source to destinationrsync -avz /home/docs user@host:/backup # Synchronize files/directories between the local and remote system with compression enabled
Search
grep
12
grep pattern files # Search for pattern in filesgrep -r pattern PATH_TO_FOLDER # Search recursively for pattern in specific FOLDER
find
12
find PATH_TO_FOLDER -name 'index*'# Find files that name start with "index"find PATH_TO_FOLDER -size +1000k # Find files larger than 1000k in folder
Compression / Archives
tar
123
tar cf archive.tar PATH_TO_FOLDER # Create tar file containing what is inside specific foldertar xf archive.tar # Extracts contenttar czf archive.tar.gz PATH_TO_FOLDER # Create a tar with gzip compression
gzip
1
gzip file # Compress file and renames it to file.gz
Permission
ls -l displays permission related information
chmod
123
chmod OCTAL PATH_TO_FILE
chmod 777 PATH_TO_FILE # Set rwx permission for owner, rwx permission for group, rwx permission for worldchmod 755 PATH_TO_FILE # Set rwx permission for owner, rx for group and world
chown
12
chown USER PATH_TO_FILE # Change owner of the filechown USER:GROUP PATH_TO_FOLDER # Change owner and group owner of the folder
Users / Groups
123456
adduser ben # Add user "ben"usermod # Modify useruserdel ben # Delete user "ben"groupadd admin # Add group "admin"useradd -c "John Doe" -g admin -m john # Create user "john" and add to group "admin"
Hardware
12345678910
free -m # Used and free memory -m for MBhdparm -i /dev/sda # Show info about disk "sda"hdparm -tT /dev/sda # Do a read speed test on disk "sda"badblocks -s /dev/sda # Test for unreadable blocks on disk "sda"cat /proc/cpuinfo # CPU modelcat /proc/meminfo # Memory infolspci -tv # List PCI deviceslsusb -tv # List USB deviceslshal # List of all devicesdmidecode # Show hardware info from the BIOS
System
1234567891011
uname -a # Display linux system informationuname -r # Display kernel release infouptime # Show how long system is runninghostname # System host namehostname -i # Display IP addresslast reboot # Show system reboot historydate # Show current date and timecal # Show this month calendarw # Display who is onlinewhoami # Display who you are logged in asfinger user # Display information about user
File Commands
123456789101112131415161718
ls -al # Display all information about files and dirspwd# Show current directory pathmkdir DIR # Create a directoryrm FILE # Delete filerm -r DIR # Delete directory recursivelyrm -f FILE # Forcefully remove filecp F1 F2 # Copy File1 to File2cp -r D1 D2 # Copy Directory1 to Directory2 (create D2 if needed)mv F1 F2 # Move files from one place to anotherln -s PATH LINK_NAME # Create symbolic link to file or dirtouch FILE # Create or update filecat > FILE # Place standard input into filemore FILE # Output the content of filehead FILE # Output the first 10 lines of filetail FILE # Output the last 10 lines of filetail -f FILE # Output the contents of file as it growsgpg -c FILE # Encrypt filegpg FILE.gpg # Decrypt file
Process Related
12345678910
ps # Display currently active processesps aux | grep 'ssh'# Find all process id related to "ssh" processpmap # Memory map of processtop # Display all running processeskill PID # Kill process with PID IDkillall NAME # Kill all NAMEd processespkill NAME # Send signal to a process with its namebg# Resumes suspended jobs without bringing them to foregroundfg# Brings the most recent job to foregroundfg N # Brings job N to the foreground