ShellPad

Personal lists of useful Linux shell commands.


System

<

p style=”padding-left:30px;”>System Info
Link: http://www.computerbob.com/guests/how_to_get_system_info_in_linux.php
facter
dmesg (boot message)
dmesg | less (view line by line)

<

p style=”padding-left:30px;”>sudo lshw (complete info about computer!)
uname -a (server info)
cat /etc/*release (OS)
lsb_release -a (OS)
arch (processor)
df -hT (mounted file systems)
cmount -l (lists all mounted filesystems)
env | sort (environmental variables)
lsmod (modules)
lspci -nnk | grep VGA (video driver)

<

p style=”padding-left:30px;”>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

<

p style=”padding-left:30px;”>Process Info
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)

<

p style=”padding-left:30px;”>Kill Process by Port
lsof -i :your_port
kill -9 your_pid

<

p style=”padding-left:30px;”>Startup / Shutdown
sudo shutdown now
sudo reboot

<

p style=”padding-left:30px;”>Command Shell History
Link: http://www.thegeekstuff.com/2008/08/15-examples-to-master-linux-command-line-history/
history
history | grep search_term
!100 (# of item to re-execute)
!previous_command (re-execute last use of that command)

top

File System

Link: http://www.thegeekstuff.com/2010/09/linux-file-system-structure
Link: http://www.ubuntugeek.com/linux-or-ubuntu-directory-structure.html

<

p style=”padding-left:30px;”>Change Directories
cd .. (back one level)
cd ~ (home)
cd / (root)
cd /dir1/dir2
cd /dir\ with\ spaces\ in\ name

<

p style=”padding-left:30px;”>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)

<

p style=”padding-left:30px;”>List USB Devices
lsusb
lsusb -s 1:4 -v

Display Contents of File
cat name_of_file

Make File
touch name_of_new_file

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

<

p style=”padding-left:30px;”>Permission
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)
awk -F":" '{ print "username: " $1 "\t\tuid:" $3 }' /etc/passwd (list all users)
cut -d: -f1,3 /etc/passwd
getent group groupname | awk -F: '{print $4}' (list users in a group)

<

p style=”padding-left:30px;”>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"

<

p style=”padding-left:30px;”>Delete Directory of Files
sudo rm -rf /path/wildcard*

<

p style=”padding-left:30px;”>Secure Copy to and from Remote System
scp .xyz ~/file1.abc /path/file2.abc user@192.168.1.0:~/remote_path/
scp -rp user@192.168.1.0:/motiontmp/search_term
~/local_path/ (copy all directories starting with search_term)

<

p style=”padding-left:30px;”>Display Part of File – Log File Examples
head -25 /var/log/messages
tail -150 /var/log/messages
cat /var/log/messages | grep "search_term"

top

Networking

<

p style=”padding-left:30px;”>Renew IP Address
sudo dhclient -r
sudo dhclient
/etc/init.d/networking restart

<

p style=”padding-left:30px;”>Change Hostname
sudo nano /etc/hostname
sudo /etc/init.d/hostname.sh start

Edit Hosts File
sudo nano /etc/hosts

<

p style=”padding-left:30px;”>Edit Network Settings Files
cd /etc/NetworkManager/system-connections

<

p style=”padding-left:30px;”>List All Ports
netstat -tulpn
cat /etc/services

<

p style=”padding-left:30px;”>List Network Interfaces
ifconfig
iwconfig
ip addr
ip addr show wlan0
ip link

<

p style=”padding-left:30px;”>Misc Network Commands
sudo arp-scan --interface=eth1 192.168.1.0/24
(Address Resolution Protocol (ARP) Scanner)
http://linux.die.net/man/1/arp-scan

nc < /dev/null; echo $? # is port open? ping domain_or_ip -c 3 traceroute domain_or_ip route PRINT (show IP routing table)

<

p style=”padding-left:30px;”>Detailed WLAN Information
iwlist
iwlist scan
iwlist wlan0 scan | less

<

p style=”padding-left:30px;”>SSH
sudo nano /etc/ssh/sshd_config (change from port 22!)
sudo service ssh restart
sudo ss -lnp | grep sshd (show ports)

top

Software Installation

<

p style=”padding-left:30px;”>Package Manager for Debian-based Ubuntu
dpkg -l
dpkg -l name_to_find

<

p style=”padding-left:30px;”>APT Package Handling Utility for Debian-based Ubuntu
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

<

p style=”padding-left:30px;”>Yum Package Management for RHEL/Oracle Linux distros
sudo yum update
yum clean packages
yum list installed | less

<

p style=”padding-left:30px;”>Uncompressing Various File Types
sudo tar xvfJ file_to_uncompress.tar.xz
sudo tar zxvf file_to_uncompress.tar.gz

<

p style=”padding-left:30px;”>Check File
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)

<

p style=”padding-left:30px;”>Execute Shell File
chmod +x install.sh
sudo ./install.sh

Find Library Version Information
pkg-config --modversion *library_to_find*

Start a Service
service service_name stop | start | restart | status (Stop/Start/Check service)
chkconfig service_name on (Set the service to start automatically)
top

Miscellaneous

Environment

<

p style=”padding-left:60px;”>Setting Environmental Variable
sudo nano ~/.bashrc
bash --login

Java

<

p style=”padding-left:60px;”>Java Info
which java
java -version

sudo update-alternatives --config java (get next #)

Execute jar File
java -jar jar_file_name.jar

Raspberry Pi

<

p style=”padding-left:60px;”>Firmware Update
Link: https://github.com/Hexxeh/rpi-update
sudo apt-get install git-core (1x)
sudo wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update && sudo chmod +x /usr/bin/rpi-update (1x)
sudo rpi-update (to update each time)

<

p style=”padding-left:60px;”>Duplicate SDHC Card
Link: https://pixhawk.ethz.ch/tutorials/omap/copy_sd_card
sudo dd if=dev/sdb of=~/sdhc-card-bu.bin (Copy to HDD)
sudo dd if=~/sdhc-card-bu.bin of=/dev/sdb (Copy back to new SDHC)

Computer Vision

<

p style=”padding-left:60px;”>OpenCV, cvBlob, FFMpeg
Link: Install
OpenCV 2.4.* in Ubuntu 12.04 Precise Pangolin

ffmpeg -version
pkg-config --modversion opencv (Which version of OpenCV?)
pkg-config --modversion cvblob (Which version of cvBlob?)
sudo ldconfig -v (Configure dynamic linker run-time bindings)

top

  1. Leave a comment

Leave a Reply

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

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: