Wednesday, April 7, 2010

Bash useful command





1. /etc/profile.       Executed automatically at login. 
2. The first file found from this list:  ̃/.bash_profile,  ̃/.bash_login, or ̃/.pro- 
file. Executed automatically at login. 
3.  ̃/.bashrc is read by every nonlogin shell. However, if invoked assh, Bash instead 
reads $ENV,for POSIX compatibility.

Filename Metacharacters 
* Match any string of zero or more characters. 
? Match any single character. 
[abc...] Match any one of the enclosed characters; a hyphen can specify a range (e.g.,a-z,A-Z,0–9).  
[!abc...] Match any character not enclosed as above. 

 ̃           Home directory of the current user. 
 ̃name Home directory of user 'name'. 
 ̃+        Current working directory ($PWD). 
 ̃-         Previous working directory ($OLDPWD).




Redirection using file descriptors 
cmd>&n         Send cmd output to file descriptor n. 
cmd m>&n     Same as previous, except that output that would normally go to file descriptor  
                         m is sent to file descriptor n instead. 
cmd>&-           Close standard output. 
cmd<&n          Take input for cmd from file descriptor n. 
cmd m<&n       Same as previous, except that input that would normally come from file
                          descriptor m comes from file descriptor n instead. 
cmd<&-            Close standard input. 
cmd<&n-         Move input file descriptor n instead of duplicating it. 
cmd>&n-        Move output file descriptor n instead of duplicating it. 
Multiple redirection 
cmd2>file       Send standard error to file standard output remains the same 
                       (e.g., the screen). 
cmd>file2>&1      Send both standard error and standard output to file. 
cmd&>file       Same as previous. Preferred form. 
cmd>&file       Same as previous. 
cmd>f1 2>f2    Send standard output to file f1 and standard error to file f2. 
cmd | tee files    Send output of cmd to standard output (usually the terminal) and 
                            to files.  
cmd 2>&1 | tee files Send standard output and error output of cmd to standard output 
                                     (usually the terminal) and to files. 


stty -a | grep erase

Create a file, /etc/inputrc for system wide use or ~/.inputrc for personal use. Actually, this is the readline initialization file, readline is a library that some programs (bash, kvt) use to read input (try bind -v to see a list of readline key and function bindings). Cut and paste the following in the file to make the Delete key delete characters under the cursor, and make Home and End work as well:


"\e[3~": delete-char
# this is actually equivalent to "\C-?": delete-char
# VT
"\e[1~": beginning-of-line
"\e[4~": end-of-line
# kvt
"\e[H":beginning-of-line
"\e[F":end-of-line
# rxvt and konsole (i.e. the KDE-app...)
"\e[7~":beginning-of-line
"\e[8~":end-of-line

Remove tab and spaces
sed 's/[\t]//g' test.txt > out.txt
sed 's/[\x09]//g' test.txt > out.txt

Zip and Unzip
tar cvf - filenames

gzip > file.tar.gz
gtar cvzf file.tar.gz filenames
tar -pczf uvobs.tar.gz /uvobs/1btsptf/core
gzip -cd mc-4.7.0.4.tar.gz | tar xfv -

Tags: Tab, Delete. Home, End



No comments:

Post a Comment

Labels