Bogumil Wrona

IT Consultant | R&D | [...] Solutions

Linux Commands

List of most common Linux commands.

Login

1
2
3
ssh user@host           # Connect to host as user
ssh -p port user@host   # Connect to host using specific port
telnet host             # Connect to the system using telnet port

Directory Traverse

1
2
3
4
cd          # Go to $HOME directory
cd ~        # Alias to: Go to $HOME directory
cd ..       # To go up one level of the directory tree
cd /var     # Change to /var directory

File Transfer

scp

1
2
3
scp file.ext host:/path #Secure copy "file.ext" to remote host "/path" folder
scp user@host:/path/*.txt /local_path   # Copy *.txt files from remote host to current system "local_path" folder
scp -r user@host:/www /www/tmp # Copy all files and folders recursively from remote server to the current system /www/tmp folder

rsync

1
2
rsync -a /home/docs /backup/ # Synchronize source to destination
rsync -avz /home/docs user@host:/backup # Synchronize files/directories between the local and remote system with compression enabled

Search

grep

1
2
grep pattern files  # Search for pattern in files
grep -r pattern PATH_TO_FOLDER # Search recursively for pattern in specific FOLDER

find

1
2
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

1
2
3
tar cf archive.tar PATH_TO_FOLDER   # Create tar file containing what is inside specific folder
tar xf archive.tar  # Extracts content
tar 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

1
2
3
chmod OCTAL PATH_TO_FILE
chmod 777 PATH_TO_FILE  # Set rwx permission for owner, rwx permission for group, rwx permission for world
chmod 755 PATH_TO_FILE  # Set rwx permission for owner, rx for group and world

chown

1
2
chown USER PATH_TO_FILE # Change owner of the file
chown USER:GROUP PATH_TO_FOLDER # Change owner and group owner of the folder

Users / Groups

1
2
3
4
5
6
adduser ben     # Add user "ben"
usermod         # Modify user
userdel 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

1
2
3
4
5
6
7
8
9
10
free -m # Used and free memory -m for MB
hdparm -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 model
cat /proc/meminfo   # Memory info
lspci -tv   # List PCI devices
lsusb -tv   # List USB devices
lshal       # List of all devices
dmidecode   # Show hardware info from the BIOS

System

1
2
3
4
5
6
7
8
9
10
11
uname -a    # Display linux system information
uname -r    # Display kernel release info
uptime      # Show how long system is running
hostname    # System host name
hostname -i # Display IP address
last reboot # Show system reboot history
date        # Show current date and time
cal         # Show this month calendar
w           # Display who is online
whoami      # Display who you are logged in as
finger user # Display information about user

File Commands

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
ls -al      # Display all information about files and dirs
pwd         # Show current directory path
mkdir DIR   # Create a directory
rm FILE     # Delete file
rm -r DIR   # Delete directory recursively
rm -f FILE  # Forcefully remove file
cp F1 F2    # Copy File1 to File2
cp -r D1 D2 # Copy Directory1 to Directory2 (create D2 if needed)
mv F1 F2    # Move files from one place to another
ln -s PATH LINK_NAME  # Create symbolic link to file or dir
touch FILE  # Create or update file
cat > FILE  # Place standard input into file
more FILE   # Output the content of file
head FILE   # Output the first 10 lines of file
tail FILE   # Output the last 10 lines of file
tail -f FILE # Output the contents of file as it grows
gpg -c FILE  # Encrypt file
gpg FILE.gpg # Decrypt file

Process Related

1
2
3
4
5
6
7
8
9
10
ps          # Display currently active processes
ps aux | grep 'ssh' # Find all process id related to "ssh" process
pmap        # Memory map of process
top         # Display all running processes
kill PID    # Kill process with PID ID
killall NAME # Kill all NAMEd processes
pkill NAME  # Send signal to a process with its name
bg # Resumes suspended jobs without bringing them to foreground
fg # Brings the most recent job to foreground
fg N # Brings job N to the foreground

Comments