Thursday, January 15, 2015

Useful and Lesser know Linux commands.


Linux command line is attractive and fascinating, and there exists a flock of Linux user who are
addictive to command Line. Linux command line can be funny and amusing. If you really get used to it and become expertise on it, you can control and almost anything in your Linux system. By referring this article, you use Google no longer to search for suitable Linux commands to complete a particular task.





Basics
cal - get calendar
date - get date
df - get disk space
free - get free space
cd - - changes working dir to previous
ll - list all including hidden files


File handling
ls
-a - list all
-t - sort by time
-s - sort by size
-r - reverse order
-d - details of current directory


file - determine files type
less - print file content
stat - print file statistics
touch - create a file
cp, mv, rm
cp dir1/* dir2 - copy all in dir1 to dir2
-i - interactive
-u - update
-v - verbose
-f - force
-r - recursive


Input Output
ln dir/file link
wc - print line, word, byte count
man
alias name=”command”
; - use to execute multiple commands at once
> - write to a file
>> - append to a file
less - show file content in editor
cat - print file content in std output
| - pipeline
sort - sort lines
unique - get unique lines


Cursor movements
ctrl + A - move to beginning
ctrl + E - move to end of the line
alt + F - one word forward
alt + B - one word backword
history -  see command history (history | grep )


file permission
id -  find out about identity
chmod - change mode
chown - change owner
chgrp - change group
chown
octal parameters - 755, 777
u, g, a, o - user types
r, w, x - operation type


Processes
ps - list snapshot of the processes
top - list updating table of processes
\ps x - show all processes
& - allows us to open a program without terminal instance
fg % - allows us to view job or program name and assign the terminal to it
kill <1> xlogo - kill a process
killall - kill all instances of a program
pstree - show process tree


Environment
printenv - print environment variables
set - shows env vars and functions
env vars
echo $USER - print username
~/.profile - this file should contain all the custom variables
source .bashrc - adding new changes done to the file to the terminal session


VI Editro
vi - open text file to edit
i - enter insert mode
esc - enter command mode
: - enter save mode
:wq - write and quit
:q! - quit without writing
h, j, k, l- move cursor left and right
x - delete character
dd - delete new line
o - get a new line and start writing
/ - search for a particular word
:$s/line/line/g -search and replace


Package Management
apt-get update
apt-cache search
apt-get install
dpkg --install - install/update from file
apt-get remove - remove a particular package
dpkg --list - listing installed package
dpkg --status - check package installed
apt-cache show - show more details about the package
dpkg --search - which package is responsible for the file name


Mounting and Unmounting
mount - show all the mounted media
df -h - shows storage details of disks in mb
fdisk - show details of disks and format them
sudo fdisk -l - show connected devices
umount - unmount from mount point


Networking
ping - send packet to particular host
tracerout
--ftp--
ftp - file transfer protocol
ftp - connect to file server
cd - change directory in file server
lcd - change directory in local server
get - download file to local directory


wget


--ssh--
ssh - connect to ssh host
scp - download a file
sudo lsof -i :5432 - port binded process


Searching for files
locate /etc/bin | grep data - locate all pathe matching the string
find -type f -name “*.png” -delete - find and delete matching files


Archiving files
gzip -tv - archive file in zip format
tar -xvf - archive file to a specific directory


Grep
grep -i ‘regexp’ - search file by ignorecase