1 - SYSTEM INFORMATION uname -a # Display Linux system information uname -r # Display kernel release information cat /etc/redhat-release # Show which version of redhat installed uptime # Show how long the system has been running + load hostname # Show system host name hostname -I # Display the IP addresses of the host last reboot # Show system reboot history date # Show the current date and time cal # Show this month's calendar w # Display who is online whoami # Who you are logged in as 2 - HARDWARE INFORMATION dmesg # Display messages in kernel ring buffer cat /proc/cpuinfo # Display CPU information cat /proc/meminfo # Display memory information free -h # Display free and used memory ( -h for human readable, -m for MB, -g for GB.) lspci -tv # Display PCI devices lsusb -tv # Display USB devices dmidecode # Display DMI/SMBIOS (hardware info) from the BIOS hdparm -i /dev/sda # Show info about disk sda hdparm -tT /dev/sda # Perform a read speed test on disk sda badblocks -s /dev/sda # Test for unreadable blocks on disk sda 3 - PERFORMANCE MONITORING AND STATISTICS top # Display and manage the top processes htop # Interactive process viewer (top alternative) mpstat 1 # Display processor related statistics vmstat 1 # Display virtual memory statistics iostat 1 # Display I/O statistics tail 100 /var/log/messages # Display the last 100 syslog messages (Use /var/log/syslog for Debian based systems.) tcpdump -i eth0 # Capture and display all packets on interface eth0 tcpdump -i eth0 'port 80' # Monitor all traffic on port 80 ( HTTP ) lsof # List all open files on the system lsof -u user # List files opened by user free -h # Display free and used memory ( -h for human readable, -m for MB, -g for GB.) watch df -h # Execute "df -h", showing periodic updates 4 - USER INFORMATION AND MANAGEMENT id # Display the user and group ids of your current user. last # Display the last users who have logged onto the system. who # Show who is logged into the system. w # Show who is logged in and what they are doing. groupadd test # Create a group named "test". useradd -c "John Smith" -m john # Create an account named john, with a comment of "John Smith" and create the user's home directory. userdel john # Delete the john account. usermod -aG sales john # Add the john account to the sales group 5 - FILE AND DIRECTORY COMMANDS ls -al # List all files in a long listing (detailed) format pwd # Display the present working directory mkdir directory # Create a directory rm file # Remove (delete) file rm -r directory # Remove the directory and its contents recursively rm -f file # Force removal of file without prompting for confirmation rm -rf directory # Forcefully remove directory recursively cp file1 file2 # Copy file1 to file2 cp -r source_directory destination # Copy source_directory recursively to destination . If destination exists, copy source_directory into destination , otherwise create destination with the contents of source_directory . mv file1 file2 # Rename or move file1 to file2 . If file2 is an existing directory, move file1 into directory file2 ln -s /path/to/file linkname # Create symbolic link to linkname touch file # Create an empty file or update the access and modification times of file. cat file # View the contents of file less file # Browse through a text file head file # Display the first 10 lines of file tail file # Display the last 10 lines of file tail -f file # Display the last 10 lines of file and "follow" the file as it grows. 6 - PROCESS MANAGEMENT ps # Display your currently running processes ps -ef # Display all the currently running processes on the system. ps -ef | grep processname # Display process information for processname top # Display and manage the top processes htop # Interactive process viewer (top alternative) kill pid # Kill process with process ID of p id killall processname # Kill all processes named processname program & # Start program in the background bg # Display stopped or background jobs fg # Brings the most recent background job to foreground fg n # Brings job n to the foreground 7 - FILE PERMISSIONS PERMISSION EXAMPLE U G W rwx rwx rwx chmod 777 filename # Use sparingly! rwx rwx r-x chmod 775 filename rwx r-x r-x chmod 755 filename rw- rw- r-- chmod 664 filename rw- r-- r-- chmod 644 filename LEGEND U = User G = Group W = World r = Read w = write x = execute - = no access 8 - NETWORKING ifconfig -a # Display all network interfaces and ip address ifconfig eth0 # Display eth0 address and details ethtool eth0 # Query or control network driver and hardware settings ping host # Send ICMP echo request to host whois domain # Display whois information for domain dig domain # Display DNS information for domain dig -x IP_ADDRESS # Reverse lookup of IP_ADDRESS host domain # Display DNS ip address for domain hostname -i # Display the network address of the host name. hostname -I # Display all local ip addresses wget http://domain.com/file # Download http://domain.com/file netstat -nutlp # Display listening tcp and udp ports and corresponding programs 9 - ARCHIVES (TAR FILES) tar cf archive.tar directory # Create tar named archive.tar containing directory . tar xf archive.tar # Extract the contents from archive.tar . tar czf archive.tar.gz directory # Create a gzip compressed tar file name archive.tar.gz . tar xzf archive.tar.gz # Extract a gzip compressed tar file. tar cjf archive.tar.bz2 directory # Create a tar file with bzip2 compression tar xjf archive.tar.bz2 # Extract a bzip2 compressed tar file. 10 - INSTALLING PACKAGES yum search keyword # Search for a package by keyword . yum install package # Install package . yum info package # Display description and summary information about package . rpm -i package.rpm # Install package from local file named package.rpm yum remove package # Remove/uninstall package . tar zxvf sourcecode.tar.gz cd sourcecode ./configure make make install # Install software from source code. 11 - SEARCH grep pattern file # Search for pattern in file grep -r pattern directory # Search recursively for pattern in directory locate name # Find files and directories by name find /home/john -name 'prefix*' # Find files in /home/john that start with "prefix". find /home -size +100M # Find files larger than 100MB in /home 12 - SSH LOGINS ssh host # Connect to host as your local username. ssh user@host # Connect to host as user ssh -p port user@host # Connect to host using port 13 - FILE TRANSFERS scp file.txt server:/tmp # Secure copy file.txt to the /tmp folder on server scp server:/var/www/*.html /tmp # Copy *.html files from server to the local /tmp folder. scp -r server:/var/www /tmp # Copy all files and directories recursively from server to the current system's /tmp folder. rsync -a /home /backups/ # Synchronize /home to /backups/home rsync -avz /home server:/backups/ # Synchronize files/directories between the local and remote system with compression enabled 14 - DISK USAGE df -h # Show free and used space on mounted filesystems df -i # Show free and used inodes on mounted filesystems fdisk -l # Display disks partitions sizes and types du -ah # Display disk usage for all files and directories in human readable format du -sh # Display total disk usage off the current directory 15 - DIRECTORY NAVIGATION cd .. # To go up one level of the directory tree. (Change into the parent directory.) cd # Go to the $HOME directory cd /etc # Change to the /etc directory
Some Useful Linux Commands
A. System Related Commands
These commands are used to view and manage Linux system-related information.
-
uname : Displays linux system information. With -a switch you can view all the information, with -r switch you can view kernel release information and with -o you can view OS information
-
cat /etc/redhat_release : Shows which version of redhat installed
-
uptime : Shows how long the system has been running
-
hostname : Shows system host name. With -i switch you can view the ip address of the machine and with -d you can view the domain name
-
last reboot : Shows system reboot history
-
date : Shows the current date and time. You can specify the format you want to view the date as well. As an example, by using 'date +%D' you can view the date in 'MM/DD/YY' format
-
cal : Shows the calendar of the current month. With -y switch you can view the calendar of the whole current year
-
w : Displays who is logged on and what they are doing
-
whoami : Shows current user id
-
finger user : Displays information about user
-
reboot : Reboots the system
-
shutdown : Shuts down the system
B. Hardware Related Commands
These commands are used to view and manage hardware-related aspects of the Linux machine.
-
dmesg : Displays all the messages from Kernel ring buffer. With -k switch you can view kernel messages and with -u you can view userspace messages
-
cat /proc/cpuinfo : Displays information about processes and CPUs of the system
-
cat /proc/meminfo : Displays details on hardware memory
-
cat /proc/interrupts : Lists the number of interrupts per CPU per I/O device
-
lshw : Displays information on hardware configuration of the system. But this command must be run as super user or it will only report partial information
-
lsblk : Displays block device related information of the machine. With -a you can view all block devices
-
free -m : Shows used and free memory (-m for MB)
-
lspci -tv : Shows information on PCI buses devices
-
lsusb -tv : Shows information on USB devices
-
dmidecode : Shows hardware info from the BIOS (vendor details)
-
hdparm -i /dev/sda : Shows info about disk sda
hdparm -tT /dev/sda : Performs a read speed test on disk sda
-
badblocks -s /dev/sda : Tests for unreadable blocks on disk sda
C. Statistic Related Commands
These set of commands are used to view various kinds of stats of the Linux system
-
mpstat 1 : Displays processors related statistics
-
vmstat 2 : Displays virtual memory statistics
-
iostat 2 : Displays I/O statistics
-
tail -n 500 /var/log/messages : Displays the last 500 kernel/syslog messages
-
tcpdump -i eth1 : Captures all packets flow on interface eth1. With -w switch you can specify a file where you can direct the output to
tcpdump -i eth0 'port 80' : Monitors all traffic on port 80 on interface eth0
-
lsof : Lists all open files belonging to all active processes
lsof -u testuser : Lists files opened by a specific user
-
free -m : Shows RAM memory details
-
watch df -h : Watches changeable disk usage continuously
D. User-Related Commands
These commands are used to manage Linux users
-
id : Shows the active user and group information. With -G switch you can view the IDs of groups
-
last : Shows a list of last logins on the system. Using -a switch you can add the hostname to the last column of the output
-
who : Shows who is logged on the system
-
groupadd admin : Adds the group "admin"
-
useradd -c "Sam Tomshi" -g admin -m sam : Creates user "sam" and adds to group "admin"
-
userdel sam : Deletes user sam
-
adduser sam : Adds user "sam"
-
usermod : Modifies user information
-
passwd user1 : Changes the password of user1
E. File Related Commands
These commands are used to handle files and directories
-
ls -al : Displays all information about files/directories. This includes displaying all hidden files as well
-
pwd : Shows current directory path
-
mkdir directory-name : Creates a directory
-
rm file-name : Deletes file
rm -r directory-name : Deletes directory recursively
rm -f file-name : Forcefully removes file
rm -rf directory-name : Forcefully removes directory recursively
-
cp file1 file2 : Copies linux files, here file1 to file2
cp -r dir1 dir2 : Copies dir1 to dir2, creates dir2 if it doesn't exist
-
mv file1 file2 : Moves files from one place to another/renames file1 to file2
-
ln -s /path/to/file-name link-name : Creates a symbolic link to file-name
-
touch file : Creates empty file
-
cat file : Prints the file content in terminal
-
more file : Display the contents of file
-
head file : Display the first 10 lines of file
-
tail file : Outputs the last 10 lines of file
tail -f file : Outputs the contents of file as it grows starting with the last 10 lines
-
gpg -c file : Encrypts file
gpg file.gpg : Decrypts file
-
cksum file : View the checksum of the file
-
diff file1 file2 : View the differences between contents of file1 and file2
-
ln -s link file : Create a soft link named link to the file
-
sort : Sorts files in alphabetical order
-
uniq : Compares adjacent lines in a file and removes/reports any duplicate lines
-
wc : Counts number of words/lines
-
dir : Lists the content of the directory
-
tee : Command for chaining and redirection
-
tr : Command for translating characters
F. Process Related Commands
These commands are used to handle Linux processes
-
ps : Displays your currently active processes
ps aux | grep 'telnet' : Displays all process ids related to telnet process
-
pmap : Display Memory map of process
-
top : Display all running processes and cpu/memory usage
-
kill pid : Kills process with mentioned pid
-
killall proc : Kills all processes named proc
-
pkill processname : Sends kill 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
G. File Permission Related Commands
These commands are used to change permissions of the files
-
chmod octal file-name : Changes the permissions of file to octal
chmod 777 /data/test.c : Sets rwx permission for owner , group and others
chmod 755 /data/test.c : Sets rwx permission for owner and rx for group and others
-
chown owner-user file : Changes owner of the file
chown owner-user:owner-group file-name : Changes owner and group owner of the file
chown owner-user:owner-group directory : Changes owner and group owner of the directory
-
chgrp group1 file : Changes the group ownership of the file to group1
G. Network Related Commands
These commands are used to view and edit network configurations related aspects of the system
-
ifconfig -a : Displays all network interface and set ip address
-
ifconfig eth0 : Displays eth0 ethernet port ip address and details
-
ip addr show : Display all network interfaces and ip addresses
-
ip address add 192.168.0.1 dev eth0 : Sets ip address of eth0 device
-
ethtool eth0 : Linux tool to show ethernet status
-
mii-tool eth0 : Linux tool to show eth0 status
-
ping host : Sends echo requests to the host to test ipv4 connection
-
whois domain : Gets who is information for domain
-
dig domain : Gets DNS nameserver information for domain
dig -x host : Reverse lookup host
-
host google.com : Lookup DNS ip address for the name
-
hostname -i : Lookup local ip address
-
wget file : Downloads file
-
netstat -tupl : Lists all active listening ports
-
nslookup : Resolves domain names to IP addresses
H. Compression / Archive Related Commands
These commands are used to compress and decompress files
-
tar cf home.tar home : Creates a tar named home.tar containing home/
tar xf file.tar : Extracts the files from file.tar
tar czf file.tar.gz files : Creates a tar with gzip compression
-
gzip file : Compresses file and renames it to file.gz
-
bzip2 -z file : Compresses file and renames it to file.bz2
bzip2 -d file.bz2 : Decompress the file
I. Package Installation Related Commands
These commands are used to manage Linux packages
-
rpm -i pkgname.rpm : Installs rpm based package
rpm -e pkgname : Removes package
-
make : Install from source file
J. Search Related Commands
These commands are used to search for files and patterns
-
grep pattern files : Searches for pattern in files
grep -r pattern dir : Searches recursively for pattern in dir
-
locate file : Finds all instances of file
-
find /home/tom -name 'index*' : Finds file names that start with "index" inside /home/tom directory
find /home -size +10000k : Finds files larger than 10000k in /home
K. Login Related Commands
These commands are used to log into another host
-
ssh user@host : Securely connect to a host as user
ssh -p port $ user@host : Connects to host using specific port
-
telnet host : Connects to the system using telnet port
L. File Transfer Related Commands
These commands are used to copy files from one system to another system
-
scp file.txt server2:/tmp : Secure copy file.txt to remote host /tmp folder
scp nixsavy@server2:/www/*.html /www/tmp : Copies *.html files from remote host to current host /www/tmp folder
scp -r nixsavy@server2:/www /www/tmp : Copies all files and folders recursively from remote server to the current system /www/tmp folder
-
rsync -a /home/apps /backup/ : Synchronizes source to destination
rsync -avz /home/apps $ saurav@192.168.10.1:/backup : Synchronize files/directories between the local and remote system with compression enabled
M. Disk Usage Related Commands
These commands are used to view disk statistics
-
df -h : Shows free space on mounted filesystems
df -i : Shows free inodes on mounted filesystems
-
fdisk -l : Shows disks partitions sizes and types
-
du -ah : Displays disk usage in human readable form
du -sh : Displays total disk usage on the current directory
-
findmnt : Displays target mount point for all filesystems
-
mount device-path mount-point : Mounts a device to the device-path
N. Directory Traverse Related Commands
These commands are used to change the directory
-
cd .. : Goes up one level of the directory tree
cd : Goes to $HOME directory
cd /test : Changes to /test directory
———————————————–END———————————————–
#Unable To release lock
E: Could not get lock /var/lib/dpkg/lock - open (11 Resource temporarily unavailable)E: Unable to lock the administration directory (/var/lib/dpkg/) is another process using it
If you try
ps aux | grep apt
that will catch processes containing the word apt, at least. If you see an apt-get process or an aptitude process that looks stuck, you can try
kill processnumber
and if that doesn’t work try
kill -9 processnumber
This should kill the process and may remove the lock. Killing an apt or aptitude process is harmless unless it is actually in the middle of package installation. In any case, if the process got stuck, you probably don’t have a choice but to kill it.
Killing a dpkg process directly, if present, is not a good idea, because if dpkg is active, it is probably manipulating the package database, and killing it may leave the package database in an inconsistent state; i.e. corrupted.
Killing an apt-get or aptitude process is in general much safer.
This should be used as last resort. If you use this carelessly you can end up with a broken system. Please try the other answers first before doing this.
You can delete the lock file with the following command:
sudo rm /var/lib/apt/lists/lock
You may also need to delete the lock file in the cache directory
sudo rm /var/cache/apt/archives/locksudo rm /var/lib/dpkg/lock
After that, try opening Synaptic again.
#Checking File Sizes
ls -l filename /* Size of the file*/ls -l * /* Size of All the files in the current directory */ls -al * /* Size of All the files including hidden files in the current directory */ls -al dir/ /* Size of All the files including hidden files in the 'dir' directory */
ls command will not list the actual size of directories. we need to use du for this purpose.
Checking Directory sizes
du -sh directory_name /* Gives you the summarized(-s) size of the directory in human readable(-h) format*/du -bsh * /* Gives you the apparent(-b) summarized(-s) size of all the files and directories in the current directory in human readable(-h) format*/
Including -h option in any of the above commands (for Ex: ls -lh * or du -sh) will give you size in human readable format (kb, mb,gb, …)
Size of a directory:
$ du -sh /tmp
Size of a file:
$ du -h /tmp/xyz
Listing Files and Their Data Format (KB, MB, GB) using ‘ls -lah’. you can also use ‘ls -all’
Linux ‘ls’ Flags Quick Reference Table
| FLAG | DESCRIPTION | EXAMPLE |
|---|---|---|
| -l | Displays file types, owner, group, size, date and filename. | ls -l |
| -a | Displays all files, including hidden files (suffixed with “.”). | ls -a |
| -h | Displays files with human readable format, e.g. 1k, 100MB, 1G. | ls -h |
The most common kill signals are: Signal Name Single Value Effect SIGHUP 1 Hangup SIGINT 2 Interrupt from keyboard SIGKILL 9 Kill signal SIGTERM 15 Termination signal SIGSTOP 17, 19, 23 Stop the process What’s nice about this is that you can use the Signal Value in place of the Signal Name. So you don’t have to memorize all of the names of the various signals. So, let’s now use the kill command to kill our instance of chrome. The structure for this command would be: to see running processes or threads >ps kill SIGNAL PID Where SIGNAL is the signal to be sent and PID is the Process ID to be killed. We already know, from our ps command that the IDs we want to kill are 3827, 3919, 10764, and 11679. So to send the kill signal, we’d issue the commands: kill -9 3827 _________ shutdown -h 10 this will machine after 10 min automatically, similary for reboot as well _________ install wine in linuxWine 2.0.1 Stable Released, Here’s How To Install it on Ubuntu________ to know a size of a directory du -sh directoryPath (disk usage -show All directoryPath) ________ history history -d 'historyNumber' !x (x = historyNumber) history -c _______ ps aux | grep processNamea = all processesors u user visibility x = all executing programs even its not a part of terminal task. https://www.cyberciti.biz/faq/mounting-windows-partition-onto-ubuntu-linux/ how to copy a line/s from one text document to another text document(suppose doc2 is 500 line doc, i want to paste 5 lines from doc1 at 120th line in doc2) from terminal ___
TASK 1: to view Windows Disk Partitions via linux terminal
#in terminal -> gedit /etc/fstab (you can use any text editor) # /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # <file system> <mount point> <type> <options> <dump> <pass> # / was on /dev/sda7 during installation UUID=4be43727-260c-4408-b75a-a7f6c7623b4b / ext4 errors=remount-ro 0 1 /swapfile none swap sw 0 0 UUID=464C596D4C59592F /media/Ddrive/ ntfs defaults 0 0 UUID=4212659E12659825 /media/Edrive/ ntfs defaults 0 0 UUID=E05A8AE55A8AB834 /media/Cdrive/ ntfs defaults 0 0 # add last three lines only # mount -av (in terminal : a=all, v=verbose)