List of most used linux commands for various purposes

I have found some time to sit together and make a list of most used linux commands by me on a personal basis. I’m sharing the same over here (this in no way intends to be a complete list or reference list, so please don’t feel offensive). I hope you can find the same useful:

System Information

dmesg (boot message)
dmesg | less (view line by line)

sudo lshw (complete hardware info about computer!)
uname -a (server info)
cat /etc/*release (OS)
df -hT (mounted file systems)
mount -l (lists all mounted filesystems)
env | sort (environmental variables)

Memory Usage
free -mto (memory in MBs totaled w/o buffers/cache)
cat /proc/meminfo (memory usage information)
cat /proc/swaps (swap information)

Init System
sudo /sbin/init –version

Process Information
ps -ef –sort uid,pid (all processes sort by user and by UID)
ps aux –sort -rss (all processes sorted my memory usage descending)
ps -efww | grep java | grep -v grep (full info all java processes but not grep)
pgrep -fl java (full info all java processes)
top (Linux tasks)

Startup / Shutdown
sudo shutdown now
sudo reboot
init init_code

Command Shell History
history | grep search_term
!100 (# of item to re-execute)
!previous_command (re-execute last use of that command)

Change Directories
cd .. (back one level)
cd ~ (home)
cd / (root)
cd /dir1/dir2
cd /dir\ with\ spaces\ in\ name

List Directories
ls .conf (.*, search_string., etc.)
lsblk (list block devices)
lsblk -fs (list block devices with filesystems info)
ls -alh (hidden files, file info, human-readable)
ls -dl */ (list all directories)
ls *.jpg -Al –block-size=M (list all JPEGs in Megabytes)

List USB Devices
lsusb -s 1:4 -v

Display Contents of File
cat name_of_file

Create File
touch name_of_new_file

Create Symbolic Link
sudo ln -s ~/path/to/ /usr/local/bin/filename

sudo su
sudo !!
sudo chmod -R 777 file_or_dir_name
sudo chmod a+rwx filename
sudo rm -rf file_or_dir_name(remove directory and contents)
sudo chown -v -R new_owner:new_owner_group dir_or_file_name
sudo cat /etc/passwd (list users)
sudo cat /etc/group (list groups)

Find File(s)
find / -name ‘file_to_find
find /path -type d -empty (find all empty directories in path)
find ~ -size +100M -ls (find all +100M files in home directory)

Search Files Recursively
grep -r “string_to_search_for”

Delete Directory of Files
sudo rm -rf /path/wildcard*

Secure Copy to and from Remote System
scp .xyz ~/ /path/ user@ip_address:~/remote_path/
scp -rp user@ip_address:/motiontmp/search_term
~/local_path/ (copy all directories starting with search_term)

Display Part of File – Log File Examples
head -25 /var/log/messages (display 25 lines from start of file)
tail -150 /var/log/messages (display 150 lines from end of file)
cat /var/log/messages | grep “search_term”

Renew IP Address
sudo dhclient -r
sudo dhclient
/etc/init.d/networking restart

Change Hostname
sudo nano /etc/hostname
sudo /etc/init.d/ start

Edit Hosts File
sudo nano /etc/hosts

Edit Network Settings Files
cd /etc/NetworkManager/system-connections

List All Ports
netstat -tulpn
cat /etc/services

List Network Interfaces
ip addr
ip addr show wlan0
ip link

Misc Network Commands
sudo arp-scan –interface=eth1 ip_address_with_mask (Address Resolution Protocol (ARP) scanner)
nc < /dev/null; echo $? # is port open?
ping domain_or_ip -c 3
traceroute domain_or_ip
route PRINT (show IP routing table)

Detailed WLAN Information
iwlist scan
iwlist wlan0 scan | less

sudo nano /etc/ssh/sshd_config (change from port 22!)
sudo service ssh restart
sudo ss -lnp | grep sshd (show ports)

Package Manager for Debian-based OS
dpkg -l
dpkg -l name_to_find

APT Package Handling Utility
sudo apt-get update && sudo apt-get upgrade
apt-cache search “partial_name_of_package”
apt-get install name_of_package
apt-get install package1 package2 package3
sudo apt-get –reinstall install package1
sudo apt-get clean
sudo apt-get autoremove

Yum Package Management Utility
sudo yum update
yum clean packages
yum list installed | less

Uncompressing Various File Types
sudo tar xvfJ file_to_uncompress.tar.xz
sudo tar zxvf file_to_uncompress.tar.gz

Check File Integrity
sha256sum file_to_check (check SHA256 (256-bit) checksums)
md5sum file_to_check (check MD5 (128-bit) checksums)
sum file_to_check (checksum and count the blocks in a file)

Execute Shell File
chmod +x (adds executable permission)
sudo ./

Find Library Version Information
pkg-config –modversion library_to_find

Setting Environmental Variable
sudo nano ~/.bashrc
bash –login

which java
java -version
sudo update-alternatives –config java (get next #)

Execute jar File
java -jar jar_file_name.jar

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s