Posts Tagged ‘Shell’
Multiple Windows in a Terminal
In Linux, Shell on October 4, 2007 at 5:59 amManage multiple terminals using screen utility
[raja@AGRAJA ~]$ screen -t name_of_screen
[raja@AGRAJA ~]$ screen -t name_of_screen2 screen_no
To navigate between screens:
1) CTRL+a
2.1) Type ” to list available screens; use arrow keys to select
[or]
2.2) Type w to list screens on the title bar for a moment.
i) CTRL+a
ii) type screen_no (it can be 0, 1, 2 … )
To scroll within a screen
1) CTRL+a
2) ESC
3) Page-Up/Page-Down
Never type ls Again
In Linux, Shell on September 27, 2007 at 6:59 amIt is compelling to type “ls” every time after
1) changing directory
2) copy/remove files
3) program is run; output file is created
etc. etc. …
Here’s a script that runs on an infinite loop that
1) allows type any command as usual (no auto-complete is available)
2) automatically “ls” after every command
# save file as cdls
# chmod 755 cdls
# type "exit" to terminate
while [ 1 ]
do
ls
read shell_command
$shell_command
done
A more useful form of the script is given below
# save as cdls
# chmod 755 cdls
# cp cdls /bin
clear
tput cup 24 0
while [ 1 ] do
tput setb 9
tput setf 0
echo --------------------------------------------------------------------------------
ls -F --color=auto
echo [`whoami` `pwd` `date`]$
tput setb 0
tput setf 7
read cmd1
$cmd1
tput cup 24 0
done
Suppress Error Message in Shell Script
In Linux, Shell on August 7, 2007 at 2:52 pmstderr
Redirect the output of stderr (descriptor 2) to /dev/null:
# save this file as testnull
# chmod 755 testnull
ls -garbage 2>/dev/null
# try ./testnull
Diagram below shows a demo
Notice that
1) redirecting to /dev/null from command line has no effect
2) redirecting error from shell script works !!
stdout
[raja@AGRAJA ~] ls 1>file_list.txt
[raja@AGRAJA ~] ls > same_file_list.txt
This is the default option during redirecting output.
i.e “1>” and “>” mean the same.
stdin
[raja@AGRAJA ~] ls 0>empty_file
[raja@AGRAJA ~] ls
The above prints to standard terminal.
Note that “empty_file” will be emptied.
Redirect everything to file
Redirect all console output texts (stdout, stderr, stdlog …) to file
For sh shell at command line: [raja@AGRAJA ~] make > & ! make.log inside shell script: illegal junk text as command > junk.spam 2>&1 [or] illegal junk text as command > & ! junk.spam
For csh shell Note: The below works on the command line, as well as inside a script [raja@AGRAJA ~] make > & ! make.log [raja@AGRAJA ~] ls > & ! files.lst [raja@AGRAJA ~] illegal junk text as command > & ! junk.spam

