0% found this document useful (0 votes)
1 views1 page

Linux Commands

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views1 page

Linux Commands

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Create tar named archive.

tar containing
# tar cf archive.tar directory
directory

# tar xf archive.tar Extract the contents from archive.tar

Display Linux system information # uname -a


Create a gzip compressed tar file name
# tar czf archive.tar.gz directory
archive.tar.gz
ARCHIVES (TAR FILES) Display kernel release information # uname -r

# tar xzf archive.tar.gz Extract a gzip compressed tar file Show how long the system has been
# uptime
running + load
# tar cjf archive.tar.bz2 directory Create a tar file with bzip2 compression
SYSTEM INFORMATION
# yum search keyword Search for a package by keyword Show system host name # hostname
# tar xjf archive.tar.bz2 Extract a bzip2 compressed tar file

# yum install package Install package Show system reboot history # last reboot

Display description and summary information Display who is online #w


# yum info package_name
about package
Who you are logged in as # whoami

Install package from local file named (RPM based distributions)


# rpm -i package.rpm
package.rpm

# yum remove package Remove/uninstall package

# tar zxvf sourcecode.tar.gz Display messages in kernel ring buffer # dmesg


# cd sourcecode
#./configure Install software from source code
# make INSTALLING PACKAGES Display CPU information # cat /proc/cpuinfo
# make install

Display memory information # cat /proc/meminfo

HARDWARE INFORMATION
# apt-cache search keyword Search for a package by keyword
Display free and used memory (-h for human
# free -h
readable, -m for MB, -g for GB.)
# apt install package_name Install package
Display and manage the top processes # top

Display description and summary information Display DMI/SMBIOS (hardware info) from
# apt show package_name (DPM based distributions) # dmidecode Display processor related statistics # mpstat 1
about package the BIOS

Display virtual memory statistics # vmstat 1


# apt remove --purge package_name Remove/uninstall package

# dpkg -i <package_name.deb> Install software from source code Display the last 100 syslog messages (Use /
# tail 100 /var/log/messages
PERFORMANCE MONITORING var/log/syslog for Debian based systems.)
AND STATISTICS

Capture and display all packets on interface


# tcpdump -i eth0
eth0

# grep pattern file Search for pattern in file

Monitor all traffic on port 80 ( HTTP ) # tcpdump -i eth0 port 80


# grep -r pattern directory Search recursively for pattern in directory

Execute "df -h", showing periodic updates # watch df –h


# locate name Find files and directories by name
SEARCH

Find files in /home/john that start with "


# find /home/john -name 'prefix*'
prefix"

Display the user and group ids of your


# id
# find /home -size +100M Find files larger than 100MB in /home current user.

Display the last users who have logged onto


# ssh host Connect to host as your local username # last
the system.
List all files in a long listing (detailed) format # ls –al
# ssh user@host Connect to host as user SSH LOGINS
Show who is logged in and what they are
#w Display the present working directory # pwd
# ssh -p port user@host Connect to host using port doing (w or who).

USER INFORMATION AND Create a directory # mkdir directory


MANAGEMENT Create a group named "test" # groupadd test

Linux
Remove (delete) file # rm file

Create an account named john, with a

Commands comment of "John Smith" and create the


user's home directory
# useradd -c "John Smith" -m john Remove the directory and its contents
recursively
# rm -r directory

Created by @0xCyberY 

Delete the john account # userdel john Force removal of file without prompting for
# rm -f file
confirmation
Add the john account to the sales group # usermod -aG sales john

Forcefully remove directory recursively # rm -rf directory

Copy file1 to file2 # cp file1 file2


Secure copy file.txt to the /tmp folder on
# scp file.txt server:/tmp
server

Copy source_directory recursively to


Copy *.html files from server to the local / destination. If destination exists, copy source_
# scp server:/var/www/*.html /tmp directory into destination, otherwise create # cp -r source_directory destination
tmp folder.
destination with the contents of source_
FILE AND DIRECTORY COMMANDS directory

Copy all files and directories recursively FILE TRANSFERS


# scp -r server:/var/www /tmp from server to the current system's /tmp
folder.
Rename or move file1 to file2. If file2 is an
existing directory, move file1 into directory # mv file1 file2
file2
# rsync -a /home /backups/ Synchronize /home to /backups/home

Synchronize files/directories between the Create symbolic link to linkname # ln -s /path/to/file linkname
# rsync -avz /home server:/backups/
local and remote system with

Display your currently running processes # ps


Create an empty file or update the access
# touch file
and modification times of file

Display all the currently running processes


# ps -ef
on the system
View the contents of file # cat file
Show free and used space on mounted
# df -h
filesystems Display and manage the top processes # top Browse through a text file # less file

Kill process with process ID of pid # kill <PID> Display the first 10 lines of file # head file
Show free and used inodes on mounted
# df -i
filesystems
PROCESS MANAGEMENT Kill all processes named processname # kill <process name> Display the last 10 lines of file # tail file

# fdisk -l Display disks partitions sizes and types DISK USAGE


Start program/script in the background # <program name>&
Display the last 10 lines of file and "follow"
# tail –f file
the file as it grows
Display disk usage for all files and directories Display stopped or background jobs # bg
# du -ah
in human readable format

Brings the most recent background job to


# fg
foreground
Display total disk usage off the current
# du -sh
directory

Brings job n to the foreground # fg n

rwx rwx rwx # chmod 777 filename

rwx rwx r-x # chmod 775 filename

PERMISSION rwx r-x r-x # chmod 755 filename

rw- rw- r-- # chmod 664 filename

rw- r-- r-- # chmod 644 filename

u= User
To go up one level of the directory tree FILE PERMISSIONS Linux chmod example 
# cd ..
(Change into the parent directory.)
g= Group

# cd ~/ Go to the $HOME directory


DIRECTORY NAVIGATION o= Others

# cd /etc Change to the /etc directory r = Read


LEGEND
w = write

x = execute

s = setuid

Display all network interfaces and ip address # ifconfig -a


- = no access
- To enter insert mode, use: i key or Ins Key.
- Type in the text. Display eth0 address and details # ifconfig <eth0>
- To leave insert mode and return to
command mode, press: <Esc>
- In command mode, save changes and exit
# vi filename <Return>  Query or control network driver and
vi by typing: :wq <Return> You are back at # ethtool <eth0>
hardware settings
the Unix prompt.
- To exit without saving changes, use :q. To
override changes and exit without saving,
use :q! Send ICMP echo request to host # ping <host-ip>
To enter vi, nano and editi file EDITING THE FILES

Display whois information for domain # whois <domain>

# nano filename 
NETWORKING Display DNS information for domain # dig <domain>

Reverse lookup of IP_ADDRESS # dig -x <IP_ADDRESS>

Display DNS ip address for domain # host <domain>

Display the network address of the host name # hostname -i

Download http://domain.com/file # wget http://domain.com/file

Display listening tcp and udp ports and


# netstat -nutlp
corresponding programs

You might also like