System commands
Disk usage
df report file system disk space blocks usage
df -i disk space inodes usage
du disk usage actual filesize
rm remove file
mkdir create directory
rmdir remove empty directory
Process commands
ps current processes
pmap PID memory map of process
kill PID kill process
kill -TERM default if no signal given (TERM=15)
pstree process tree
free memory usage
ipcs interprocess communication protocol
top displays linux current tasks
Thursday, August 5, 2010
Monday, July 19, 2010
Bash colours
Normal Colours
echo -e "\e[0;30m" Black
echo -e "\e[0;31m" Red
echo -e "\e[0;32m" Green
echo -e "\e[0;33m" Yellow
echo -e "\e[0;34m" Blue
echo -e "\e[0;35m" Purple
echo -e "\e[0;36m" Cyan
echo -e "\e[0;37m" White
Bold Colours
echo -e "\e[1;30m" Black
echo -e "\e[1;31m" Red
echo -e "\e[1;32m" Green
echo -e "\e[1;33m" Yellow
echo -e "\e[1;34m" Blue
echo -e "\e[1;35m" Purple
echo -e "\e[1;36m" Cyan
echo -e "\e[1;37m" White
Coloured with underline
echo -e "\e[4;30m"
echo -e "\e[4;31m"
echo -e "\e[4;32m" Green
echo -e "\e[4;33m"
echo -e "\e[4;34m" Blue
echo -e "\e[4;35m" Purple
echo -e "\e[4;36m" Cyan
echo -e "\e[4;37m" White
Background Colours
echo -e "\e[40m" Black
echo -e "\e[41m" Red
echo -e "\e[42m" Green
echo -e "\e[43m" Yellow
echo -e "\e[44m" Blue
echo -e "\e[45m" Purple
echo -e "\e[46m" Cyan
echo -e "\e[47m" White
Reset as of terminal colours
echo -e "\e[0m" Reset Text
The use of m indicates end of the codes
you can try out for combination
echo -e "\e[1;31m"Bold Red"\e[4;33m"Bold Yellow Underlined"\e[0;45m"Purple Background"\e[0m"
echo -e "\e[0;30m" Black
echo -e "\e[0;31m" Red
echo -e "\e[0;32m" Green
echo -e "\e[0;33m" Yellow
echo -e "\e[0;34m" Blue
echo -e "\e[0;35m" Purple
echo -e "\e[0;36m" Cyan
echo -e "\e[0;37m" White
Bold Colours
echo -e "\e[1;30m" Black
echo -e "\e[1;31m" Red
echo -e "\e[1;32m" Green
echo -e "\e[1;33m" Yellow
echo -e "\e[1;34m" Blue
echo -e "\e[1;35m" Purple
echo -e "\e[1;36m" Cyan
echo -e "\e[1;37m" White
Coloured with underline
echo -e "\e[4;30m"
echo -e "\e[4;31m"
echo -e "\e[4;32m" Green
echo -e "\e[4;33m"
echo -e "\e[4;34m" Blue
echo -e "\e[4;35m" Purple
echo -e "\e[4;36m" Cyan
echo -e "\e[4;37m" White
Background Colours
echo -e "\e[40m" Black
echo -e "\e[41m" Red
echo -e "\e[42m" Green
echo -e "\e[43m" Yellow
echo -e "\e[44m" Blue
echo -e "\e[45m" Purple
echo -e "\e[46m" Cyan
echo -e "\e[47m" White
Reset as of terminal colours
echo -e "\e[0m" Reset Text
The use of m indicates end of the codes
you can try out for combination
echo -e "\e[1;31m"Bold Red"\e[4;33m"Bold Yellow Underlined"\e[0;45m"Purple Background"\e[0m"
Monday, June 14, 2010
convert dos file to linux file
We often use the commands to convert the dos file to linux, using the commands
dos2unix - DOS/MAC to UNIX text file format converter
unix2dos - UNIX to DOS text file format converter
The conversion can be done by the commands tr and sed.
$ tr -d \\r < dos-file.txt > temp.txt && mv temp.txt dos-file.txt
here dos-file.txt will be converted to unix fileformat, temp.txt is the temporary file created and then renamed to dos-file.txt
$ sed -e 's/$/\r/g' unix-file.txt > temp.txt && mv temp.txt unix-file.txt
here unix-file.txt will be converted to dos fileformat, temp.txt is the temporary file created and then renamed to unix-file.txt.
dos2unix - DOS/MAC to UNIX text file format converter
unix2dos - UNIX to DOS text file format converter
The conversion can be done by the commands tr and sed.
$ tr -d \\r < dos-file.txt > temp.txt && mv temp.txt dos-file.txt
here dos-file.txt will be converted to unix fileformat, temp.txt is the temporary file created and then renamed to dos-file.txt
$ sed -e 's/$/\r/g' unix-file.txt > temp.txt && mv temp.txt unix-file.txt
here unix-file.txt will be converted to dos fileformat, temp.txt is the temporary file created and then renamed to unix-file.txt.
Thursday, June 3, 2010
find: files between dates
Finding the files in the date range
check man find for more
find - search for files in a directory hierarchy
-mmin n
File's data was last modified n minutes ago.
-mtime n
File's data was last modified n*24 hours ago.
-type c
File is of type c:
b block (buffered) special
c character (unbuffered) special
d directory
p named pipe (FIFO)
f regular file
l symbolic link; this is never true if the -L option or the -follow option
is in effect, unless the symbolic link is broken. If you want to search
for symbolic links when -L is in effect, use -xtype.
s socket
D door (Solaris)
-name pattern
Base of file name (the path with the leading directories removed) matches shell
pattern pattern. The metacharacters (`*', `?', and `[]') match a `.' at the
start of the base name (this is a change in findutils-4.2.2; see section STAN‐
DARDS CONFORMANCE below). To ignore a directory and the files under it, use
-prune; see an example in the description of -path. Braces are not recognised
as being special, despite the fact that some shells including Bash imbue braces
with a special meaning in shell patterns. The filename matching is performed
with the use of the fnmatch(3) library function. Don't forget to enclose the
pattern in quotes in order to protect it from expansion by the shell.
Listing the files with date
-rw-r----- 1 syslog adm 487017 2010-05-30 08:02 messages.1
-rw-r----- 1 syslog adm 646 2010-05-23 07:59 messages.2.gz
-rw-r----- 1 syslog adm 415 2010-05-16 07:47 messages.3.gz
-rw-r----- 1 syslog adm 55321 2010-05-09 07:49 messages.4.gz
$ find . -mtime 4./messages.1
-mtime -11 gives the files created from now till 11 days
./messages.1
-mtime +11 gives files created after the 11th day
./messages.4.gz
now when we want the files created from 11th day and older or rather above ten days then we can have
./messages.3.gz
./messages.4.gz
if we want to have list of files created 10 days before whose name begins with messages
-rw-r----- 1 syslog adm 415 2010-05-16 07:47 ./messages.3.gz
-rw-r----- 1 syslog adm 55321 2010-05-09 07:49 ./messages.4.gz
I would always suggest to have the -a -type f option so you are surely working on files only, as ls -l will in sub-directories.
check man find for more
find - search for files in a directory hierarchy
-mmin n
File's data was last modified n minutes ago.
-mtime n
File's data was last modified n*24 hours ago.
-type c
File is of type c:
b block (buffered) special
c character (unbuffered) special
d directory
p named pipe (FIFO)
f regular file
l symbolic link; this is never true if the -L option or the -follow option
is in effect, unless the symbolic link is broken. If you want to search
for symbolic links when -L is in effect, use -xtype.
s socket
D door (Solaris)
-name pattern
Base of file name (the path with the leading directories removed) matches shell
pattern pattern. The metacharacters (`*', `?', and `[]') match a `.' at the
start of the base name (this is a change in findutils-4.2.2; see section STAN‐
DARDS CONFORMANCE below). To ignore a directory and the files under it, use
-prune; see an example in the description of -path. Braces are not recognised
as being special, despite the fact that some shells including Bash imbue braces
with a special meaning in shell patterns. The filename matching is performed
with the use of the fnmatch(3) library function. Don't forget to enclose the
pattern in quotes in order to protect it from expansion by the shell.
Listing the files with date
$ ls -l
-rw-r----- 1 syslog adm 1555 2010-06-03 07:54 messages-rw-r----- 1 syslog adm 487017 2010-05-30 08:02 messages.1
-rw-r----- 1 syslog adm 646 2010-05-23 07:59 messages.2.gz
-rw-r----- 1 syslog adm 415 2010-05-16 07:47 messages.3.gz
-rw-r----- 1 syslog adm 55321 2010-05-09 07:49 messages.4.gz
-mtime 4 gives the file created exactly 4 days ago (4*24)
$ find . -mtime 4
$ date -d "4 days ago"
Sun May 30 16:15:14 IST 2010-mtime 11 gives the file created exactly 11 days ago (11*24)
$ find . -mtime 11
./messages.2.gz$ date -d "11 days ago"
Sun May 23 16:16:04 IST 2010-mtime -11 gives the files created from now till 11 days
$ find . -mtime -11
./messages./messages.1
-mtime +11 gives files created after the 11th day
$ find . -mtime +11
./messages.3.gz./messages.4.gz
now when we want the files created from 11th day and older or rather above ten days then we can have
$ find . -mtime +10
./messages.2.gz./messages.3.gz
./messages.4.gz
if we want to have list of files created 10 days before whose name begins with messages
$find . -mtime +10 -a -name "messages*" -a -type f -exec ls -l {} \;
-rw-r----- 1 syslog adm 646 2010-05-23 07:59 ./messages.2.gz-rw-r----- 1 syslog adm 415 2010-05-16 07:47 ./messages.3.gz
-rw-r----- 1 syslog adm 55321 2010-05-09 07:49 ./messages.4.gz
I would always suggest to have the -a -type f option so you are surely working on files only, as ls -l will in sub-directories.
Wednesday, June 2, 2010
sed: for the text between matching pattern
sed -ne '/IC/,/EI/p' country-codes.txt where IC is the first pattern and IE is the last for the file having country codes
file:country-codes.txt
GY,Guyana
HA,Haiti
HO,Honduras
HU,Hungary
IC,Iceland
IN,India
ID,Indonesia
IR,Iran
IZ,Iraq
EI,Ireland
IM,Isle of Man
IS,Israel
IT,Italy
command: sed -ne '/IC/,/EI/p' country-codes.txt
IC,Iceland
IN,India
ID,Indonesia
IR,Iran
IZ,Iraq
EI,Ireland
file:country-codes.txt
GY,Guyana
HA,Haiti
HO,Honduras
HU,Hungary
IC,Iceland
IN,India
ID,Indonesia
IR,Iran
IZ,Iraq
EI,Ireland
IM,Isle of Man
IS,Israel
IT,Italy
command: sed -ne '/IC/,/EI/p' country-codes.txt
IC,Iceland
IN,India
ID,Indonesia
IR,Iran
IZ,Iraq
EI,Ireland
Friday, March 26, 2010
ls --color Decorating Directory Listing
The change the colours for your directory listing
Edit file: /etc/DIR_COLORS, copy the only changed ones in ~/.dircolors.
Next login, you get it.
file: /etc/DIR_COLORS
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
#NORMAL 00 # no color code at all
#FILE 00 # normal file, use no color at all
RESET 0 # reset to "normal" color
DIR 01;34 # directory
LINK 01;36 # symbolic link (If you set this to 'target' instead of a
# numerical value, the color is as for the file pointed to.)
Edit file: /etc/DIR_COLORS, copy the only changed ones in ~/.dircolors.
Next login, you get it.
file: /etc/DIR_COLORS
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
#NORMAL 00 # no color code at all
#FILE 00 # normal file, use no color at all
RESET 0 # reset to "normal" color
DIR 01;34 # directory
LINK 01;36 # symbolic link (If you set this to 'target' instead of a
# numerical value, the color is as for the file pointed to.)
Monday, March 1, 2010
FTP GET remote file timestamp
Check the remote server file time
login to ftp server
ftp servername
do
ls -ltr
will show list of files say we have
ftp> ls -ltr
227 Entering Passive Mode (10,146,172,50,66,132)
150 Here comes the directory listing.
-rw-r--r-- 1 50005 50005 5250 Mar 01 08:15 tech-talk
226 Directory send OK.
use modtime filename to check the file modified timestamp, ftp always shows in GMT time
ftp> modtime tech-talk
tech-talk 03/01/2010 08:15:00 GMT
login to ftp server
ftp servername
do
ls -ltr
will show list of files say we have
ftp> ls -ltr
227 Entering Passive Mode (10,146,172,50,66,132)
150 Here comes the directory listing.
-rw-r--r-- 1 50005 50005 5250 Mar 01 08:15 tech-talk
226 Directory send OK.
use modtime filename to check the file modified timestamp, ftp always shows in GMT time
ftp> modtime tech-talk
tech-talk 03/01/2010 08:15:00 GMT
Subscribe to:
Posts (Atom)