!! recall the last command !cmd recall the last command starting by cmd !$ last argument of the last command CTRL + r search in the last commands CTRL + a jump to the start of the line CTRL + e jump to the end of the line CTRL + u delete backward from cursor CTRL + k delete forward from cursor CTRL + w delete the word before the cursor
Store in variables output and status of a bash command
output=$(command) status=$?
A command succeeds if status code = 0
#! /bin/bash program > results << !BLOC! param1 param2 param3 !BLOC!The tags !BLOC! delineate parameters (param1, param2 and param3) send to program. Output is send to results file.
Define date and time manually:
date -s "MM/JJ/AAAA HH:MM:SS"
One can also synchronize to a time server (ntp package),
for instance pool.ntp.org or europe.pool.ntp.org.
The configuration of ntp is done in /etc/ntp.conf. The time synchronization daemon is loaded via
/etc/init.d/ntpd restart or /etc/init.d/ntp restart
To check if the synchonization is working: ntpq -np, columns 'when' and 'reach' should not be null or undefined.
List of French time servers
Binary ----- Logic --- Decimal 000 -------- (---) ------- 0 001 -------- (--x) ------- 1 010 -------- (-w-) ------- 2 011 -------- (-wx) ------- 3 100 -------- (r--) ------- 4 101 -------- (r-x) ------- 5 110 -------- (rw-) ------- 6 111 -------- (rwx) ------- 7chown to change owner: chown group file or chown login.group file or chown login file
session required /lib/security/pam_limits.soAnd edit /etc/security/limits.conf and add:
@users hard nproc 23 @users hard data 2000 @users hard nofile 20 @users hard stack 4000 @users hard core 8000 @users hard fsize 100000
echo "done" | mail -s "process in $HOSTNAME done" user@domain.comFor a more sophisticated output, one can use a bash script:
#! /bin/bash mail -s "error with $USER" root@domain.com << !message! Hello, There is an error with $USER on $HOSTNAME computer. Can you fix it ? By by !message!
/sbin/fuser -v /dev/dsp0List processes using the cdrom drive (usefull for a clean unmount):
/sbin/fuser -v /mnt/cdromOption -k instead of -v automatically kills processes found.
color-xterm -e tail -f /var/log/message &or
color-xterm -ls -geometry 80x5+45+705 -rv -sb -name "System messages" -fn 5x7 -T "System messages" -e tail -f /var/log/messages &One can also redirect syslog outputs toward a terminal (for instance tty8). Add kern.* /dev/tty8 in /etc/syslog.conf.
ifconfig : list network interfaces "up" (activated) ifconfig -a : list all network interfaces dhclient eth0 : get an ip address from DHCP for eth0 interface ifup eth0 : activate eth0 interface
/dev/hda1 /mnt/win_c vfat iocharset=iso8859-15,codepage=850,umask=0,uid=501,gid=501 0 0The uid and gid may be found in /etc/passwd (first two numbers of the user line).
cat /proc/cpuinfo gives information of the CPU(s) (number of processors, model and flags)
cat /proc/cpuinfo |grep processor |wc -l outputs the number of cpus.
/sbin/lspci gives information on the PCI bridges
/sbin/lspci |grep 'PCI Express x16' outputs the PCI bridge for video card (PCI Express 16x)
/sbin/lspci |grep VGA gives info on the video card
glxinfo |grep OpenGL gives more info on nVidia video card
cat /proc/meminfo |grep 'MemTotal' outputs the total RAM
fdisk -l (as root) lists all connected hard drives (internal and external)
Install the package test: yum install test
Install the package test.rpm: rpm -ivh test.rpm
Remove the package test: yum remove test or rpm -e test
List packages available for installation: yum list
List installed packages: yum list installed or rpm -qa
List all packages (installed and available): yum list all
List updated packages: yum list updates
Search the package test: yum list *test*
Find if package test is installed : yum list installed test or rpm -qa |grep test
List and location of files contained in the package test.rpm: rpm -qlp test.rpm
List and location of files contained in the installed package test: rpm -ql test
Find which package provides the file /path/to/file: yum whatprovides /path/to/file or rpm -qf /path/to/file
Check the packages to be updated: yum check-update
Update the package test: yum update test
Update the package test.rpm: rpm -Uvh test.rpm
Update all installed packages: yum update
Clean all installed packages from disk cache: yum clean all
alias xmgrace="LC_NUMERIC=C xmgrace"Either redefine the decimal separator globally (in .bashrc file):
export LC_NUMERIC=C
pbsnodes -l freeGet list of active (working) nodes
pbsnodes -l activeGet number of available cores (assuming a cluster of 13 nodes x 16 cores)
qstat -n | sed 's/node/node\n/g' | grep -c node | awk '{print 13*16 - $1}'
uname -mFind if a binary is compiled for 32 or 64 bits:
file -be elf /usr/bin/neditanswer could be
ELF 64-bit LSB executable, x86-64, version 1 (SYSV)or
ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV)
for i in *.txt; do mv $i ${i%txt}dat; doneor
rename 's/\.txt$/\.dat/' *.txt
for i in *.dat; do mv "$i" `echo $i | tr ' ' '_'`; done
pdftoppm file.pdf page convert page-000001.ppm page.png rm page-000001.ppm
pdf2ps -sPAPERSIZE=a4 file.pdf file.ps psbook file.ps | psnup -2 | a2ps -1 -s tumble -o booklet.psPrint on both side with the option "long edge (standard)". If the original document is not in the A4 format (for instance 14,88 cm x 20,98 cm), we have to do then:
pdf2ps file.pdf file.ps psbook file.ps | psnup -2 -W18.88cm -H20.98cm -pa4 | a2ps -1 -s tumble -o booklet.ps
pdfnup input.pdf --nup 1x3 --frame true --scale 0.96 pdfnup input.pdf --nup 1x3 --frame true --scale 0.96 --outfile output.pdf
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dBATCH -sOutputFile=output.pdf input.pdfVerbosity can be decreased with the -dQUIET option
pdfimages file.pdf picture for i in picture-*.ppm; do convert $i ${i%ppm}png; done
pstopnm -xborder=0 -yborder=0 -xsize=new-size-x -ysize=new-size-y -stdout file.eps > file.ppm pnmtopng file.ppm > file.png rm -f file.ppmor
mogrify -density 120 -rotate 90 -format png file.ps
for i in *.mp3; do lame --decode $i `basename $i .mp3`.wav; done
for i in *.ogg ; do ogg123 -d wav -f `basename $i .ogg`.wav $i; done
mplayer file.wma -ao pcm -aofile file.wavor
mplayer -vo null -vc dummy -af resample=44100 -ao pcm -waveheader file.wma -aofile file.wav
ffmpeg -i input.3gp -f avi -vcodec xvid -acodec mp3 output.avior with more advanced option :
ffmpeg -i video.3gp -b 250 -s 160×120 -r 15 -f avi -an video.avi
pdfnup test.pdf --nup 2x2 --orient landscape --frame true
pdfnup is provided with the package pdfjam.
mplayer -dumpstream -dumpfile test.wmv -nocache mms://stream-address.wmvor
mencoder mms://stream-address.wmv -oac copy -ovc copy -o toto.avi
convert -background white -flatten pic.png pic_white.png
TestA 3 11 TestB 26 45 TestA 7 87 TestB 18 14To sum numbers of the second column of all lines starting by "TestA":
awk '/TestA/ {sum+=$2; print sum}' fileTo print numbers of the second column and their sum:
awk '/TestA/ {sum+=$2; printf "%d %d\n", $2, sum}' file
dd if=/dev/cdrom of=image.isoor
cdda2wav -D /dev/cdrom -s -O wav -S 1à -B cdrecord -v fs=6m speed=10 dev=0,0,0 -audio *.wav
With /dev/dvd the DVD-ROM drive.
Files:
growisofs -dvd-compat -speed=2 -Z /dev/dvd -R -J files
Iso image:
growisofs -dvd-compat -speed=2 -Z /dev/dvd=file.iso
Directory content:
growisofs -dvd-compat -speed=2 -Z /dev/dvd -R -J directory_name
One or several directories (with their directory name):
growisofs -dvd-compat -speed=2 -Z /dev/dvd -R -J -graft-points /dir1=/path/to/dir1 /dir2=/path/to/dir2
Clean DVD:
dvd+rw-format -force /dev/dvd
Note: is filenames are too long, use the -joliet-long option instead of -J
Create the file .gtkrc-2.0 in the home directory and append the line
gtk-font-name = "Arial 11"
Scripts have to be Unix type files (and not Dos type).
Download of a directory recursively: wget -r -np url
List existing crontab: crontab -l
Edit contrab: contrab -e
Automatically append a new job to crontab:
crontab -l > old.cron echo "# add new cron job at 3:00 AM" > append.cron echo "0 3 * * * script.sh >& /tmp/script.log" >> append.cron cat old.cron append.cron > new.cron crontab new.cron
Build a SSH connection directly from computerA to computerC via serverB (computerA — serverB — computerC):
ssh -L 2222:computerC:22 login@serverBAnd in a different shell:
ssh -X localhost -p 2222
The local port (2222 here) must be > to 1024 since port < 1024 are reserved to root.
ssh-keygen -t rsaAccept all default choices and leave an empty passphrase.
ssh-copy-id -i ~/.ssh/id_rsa.pub computerBEnter one last time your password of userB on computerB to accept the copy.
Search for text files (*.txt) and search into:
find ./path/ -name '*.txt' | xargs grep 'string'
Search text files (*.txt) and remove:
find ./path/ -name '*.txt' -exec rm {} \;
Search files with size bigger than 5 Mb and sort them by size:
find ./ -size +5M -type f -print0 | xargs -0 ls -Ssh
Search files modified less than last 2 days ago with size bigger than 100 kb and archive:
find ./path/ -type f -mtime -2 -size +100k | xargs tar -zcvf archive.tgz
Search all pdf files and copy them in a directory:
find ./path/ -name "*pdf" -print0 |xargs -0 cp -t ./directory/
shred -v -n 1 -z /dev/hdc -v : show progress -n 1 : overwrite hard disk with one pass of random data -z : finish cleaning with one pass of zerosOne can clean full hard disk (/dev/hdc) or single partition (/dev/hdc1).
lsb_release -a