ShellPad

Personal lists of useful Linux shell commands.


System

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

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

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

Kill Process by Port
lsof -i :your_port
kill -9 your_pid

Startup / Shutdown
sudo shutdown now
sudo reboot

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

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

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

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
~/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

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

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

Change Hostname
sudo nano /etc/hostname
sudo /etc/init.d/hostname.sh 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
ifconfig
iwconfig
ip addr
ip addr show wlan0
ip link

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

Detailed WLAN Information
iwlist
iwlist scan
iwlist wlan0 scan | less

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

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

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

Yum Package Management for RHEL/Oracle Linux distros
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
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 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

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

Java

Java Info
which java
java -version

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

Execute jar File
java -jar jar_file_name.jar

Raspberry Pi

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

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

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 )

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: