DISCLAIMER : Please note that blog owner takes no responsibility of any kind for any type of data loss or damage by trying any of the command/method mentioned in this blog. You may use the commands/method/scripts on your own responsibility.If you find something useful, a comment would be appreciated to let other viewers also know that the solution/method work(ed) for you.
Runs previous command replacing the typo
when we run a command with a typo, we can correct the typo and re-run the command by the following command.
^wrong^right
Here are the examples:
The man command is wrongly typed as many
[root@test /]# many head
-bash: many: command not found
The y is replaced with empty character.
[root@test /]# ^y
man head
--------------------------------------------------------------
Here man is typed as men
[root@test /]# men head
-bash: men: command not found
the letter e is replaced with a and then the command executes.
[root@test /]# ^e^a
man head
^wrong^right
Here are the examples:
The man command is wrongly typed as many
[root@test /]# many head
-bash: many: command not found
The y is replaced with empty character.
[root@test /]# ^y
man head
--------------------------------------------------------------
Here man is typed as men
[root@test /]# men head
-bash: men: command not found
the letter e is replaced with a and then the command executes.
[root@test /]# ^e^a
man head
Pushd and popd in bash
Push your present working directory to a stack that you can pop later
If are a Bash user and you are in a directory and need to go else where for a while but don't want to lose where you were, use pushd instead of cd.
cd /home/complicated/path/.I/dont/want/to/forget
pushd /tmp
cd thing/in/tmp
popd (returns you to /home/complicated/path/.I/dont/want/to/forget)
If are a Bash user and you are in a directory and need to go else where for a while but don't want to lose where you were, use pushd instead of cd.
cd /home/complicated/path/.I/dont/want/to/forget
pushd /tmp
cd thing/in/tmp
popd (returns you to /home/complicated/path/.I/dont/want/to/forget)
awk one-liner Tips
Print column1, column5 and column7 of a data file or output of any columns list
$awk ‘{print $1, $5, $7}’ data_file
$cat file_name |awk ‘{print $1 $5 $7}’
$ls –al |awk ‘{print $1, $5, $7}’ -- Prints file_permissions,size and date
Syntax of running an awk program
Awk ‘program’ input file(s)
List all files names whose file size greater than zero.
$ls –al |awk ‘$5 > 0 {print $9}’
List all files whose file size equal to 512bytes.
$ls –al |awk ‘$5 == 512 {print $9}’
print all lines
$awk ‘{print }’ file_name
$awk ‘{print 0}’ file_name
Number of lines in a file
$awk ‘ END {print NR}’ file_name
Number of columns in each row of a file
$awk ‘ {print NF’} file_name
Sort the output of file and eliminate duplicate rows
$awk ‘{print $1, $5, $7}’ |sort –u
List all file names whose file size is greater than 512bytes and owner is "oracle"
$ls –al |awk ‘$3 == "oracle" && $5 > 512 {print $9}’
List all file names whose owner could be either "oracle" or "root"
$ls –al |awk ‘$3 == "oracle" || $3 == "root" {print $9}’
list all the files whose owner is not "oracle
$ls –al |awk ‘$3 != "oracle" {print $9}’
List all lines which has atlease one or more characters
$awk ‘NF > 0 {print }’ file_name
List all lines longer that 50 characters
$awk ‘length($0) > 50 ‘{print }’ file_name
List first two columns
$awk ‘{print $1, $2}’ file_name
Swap first two columns of a file and print
$awk ‘{temp = $1; $1 = $2; $2 = temp; print }’ file_name
Replace first column as "ORACLE" in a data file
$awk ‘{$1 = "ORACLE"; print }’ data_file
Remove first column values in a data file
$awk ‘{$1 =""; print }’ data_file
Calculate total size of a directory in Mb
$ls –al |awk ‘{total +=$5};END {print "Total size: " total/1024/1024 " Mb"}’
Calculate total size of a directory including sub directories in Mb
$ls –lR |awk ‘{total +=$5};END {print "Total size: " total/1024/1024 " Mb"}’
Find largest file in a directory including sub directories
$ls –lR |awk ‘{print $5 "\t" $9}’ |sort –n |tail -1
$awk ‘{print $1, $5, $7}’ data_file
$cat file_name |awk ‘{print $1 $5 $7}’
$ls –al |awk ‘{print $1, $5, $7}’ -- Prints file_permissions,size and date
Syntax of running an awk program
Awk ‘program’ input file(s)
List all files names whose file size greater than zero.
$ls –al |awk ‘$5 > 0 {print $9}’
List all files whose file size equal to 512bytes.
$ls –al |awk ‘$5 == 512 {print $9}’
print all lines
$awk ‘{print }’ file_name
$awk ‘{print 0}’ file_name
Number of lines in a file
$awk ‘ END {print NR}’ file_name
Number of columns in each row of a file
$awk ‘ {print NF’} file_name
Sort the output of file and eliminate duplicate rows
$awk ‘{print $1, $5, $7}’ |sort –u
List all file names whose file size is greater than 512bytes and owner is "oracle"
$ls –al |awk ‘$3 == "oracle" && $5 > 512 {print $9}’
List all file names whose owner could be either "oracle" or "root"
$ls –al |awk ‘$3 == "oracle" || $3 == "root" {print $9}’
list all the files whose owner is not "oracle
$ls –al |awk ‘$3 != "oracle" {print $9}’
List all lines which has atlease one or more characters
$awk ‘NF > 0 {print }’ file_name
List all lines longer that 50 characters
$awk ‘length($0) > 50 ‘{print }’ file_name
List first two columns
$awk ‘{print $1, $2}’ file_name
Swap first two columns of a file and print
$awk ‘{temp = $1; $1 = $2; $2 = temp; print }’ file_name
Replace first column as "ORACLE" in a data file
$awk ‘{$1 = "ORACLE"; print }’ data_file
Remove first column values in a data file
$awk ‘{$1 =""; print }’ data_file
Calculate total size of a directory in Mb
$ls –al |awk ‘{total +=$5};END {print "Total size: " total/1024/1024 " Mb"}’
Calculate total size of a directory including sub directories in Mb
$ls –lR |awk ‘{total +=$5};END {print "Total size: " total/1024/1024 " Mb"}’
Find largest file in a directory including sub directories
$ls –lR |awk ‘{print $5 "\t" $9}’ |sort –n |tail -1
How to check if I am running a uniprocessor kernel or a multiprocessor kernel?
/unix is a symbolic link to the booted kernel. To find out what kernel mode is running, enter ls -l /unix and see what file /unix it links to.
The following are the three possible outputs from the ls -l /unix command and their corresponding kernels:
/unix -> /usr/lib/boot/unix_up # 32 bit uniprocessor kernel
/unix -> /usr/lib/boot/unix_mp # 32 bit multiprocessor kernel
/unix -> /usr/lib/boot/unix_64 # 64 bit multiprocessor kernel
The following are the three possible outputs from the ls -l /unix command and their corresponding kernels:
/unix -> /usr/lib/boot/unix_up # 32 bit uniprocessor kernel
/unix -> /usr/lib/boot/unix_mp # 32 bit multiprocessor kernel
/unix -> /usr/lib/boot/unix_64 # 64 bit multiprocessor kernel
Memory utilisation of processes in AIX
For memory information, we use the command svmon.
svmon shows the total usage of physical and paging memory.
Command to display top ten processes and users
svmon -P -v -t 10 | more
Displaying top CPU_consuming processes:
ps aux | head -1; ps aux | sort -rn +2
Displaying top memory-consuming processes:
ps aux | head -1; ps aux | sort -rn +3 | head
Displaying process in order of priority:
ps -eakl | sort -n +6 | head
Displaying the process in order of time
ps vx | head -1;ps vx | grep -v PID | sort -rn +3
Displaying the process in order of real memory use
ps vx | head -1; ps vx | grep -v PID | sort -rn +6
Displaying the process in order of I/O
ps vx | head -1; ps vx | grep -v PID | sort -rn +4
svmon shows the total usage of physical and paging memory.
Command to display top ten processes and users
svmon -P -v -t 10 | more
Displaying top CPU_consuming processes:
ps aux | head -1; ps aux | sort -rn +2
Displaying top memory-consuming processes:
ps aux | head -1; ps aux | sort -rn +3 | head
Displaying process in order of priority:
ps -eakl | sort -n +6 | head
Displaying the process in order of time
ps vx | head -1;ps vx | grep -v PID | sort -rn +3
Displaying the process in order of real memory use
ps vx | head -1; ps vx | grep -v PID | sort -rn +6
Displaying the process in order of I/O
ps vx | head -1; ps vx | grep -v PID | sort -rn +4
Execute a command without saving it in the history
Prepending one or more spaces to your command won't be saved in history.
It i very useful for hiding your commands which consists of passwords on the commandline.
This is tested in bash shell and works successfully.
Example :
$ echo this goes to history
this goes to history
$ echo this wont go to history
this wont go to history
$ history
1 echo this goes to history
2 history
The manual page of "bash" shows as follows:
kill -9 $$
this exits bash without saving the history. unlike explicitly disabling the history in some way, this works anywhere, and it works if you decide *after* issuing the command you don't want logged, that you don't want it logged
... $ ( or ${$} ) is the pid of the current bash instance
this also works perfectly in shells that don't have $ if you do something like
It i very useful for hiding your commands which consists of passwords on the commandline.
This is tested in bash shell and works successfully.
Example :
$ echo this goes to history
this goes to history
$ echo this wont go to history
this wont go to history
$ history
1 echo this goes to history
2 history
The manual page of "bash" shows as follows:
HISTCONTROL
A colon-separated list of values controlling how commands are
saved on the history list. If the list of values includes
ignorespace, lines which begin with a space character are not
saved in the history list. A value of ignoredups causes lines
matching the previous history entry to not be saved. A value
of ignoreboth is shorthand for ignorespace and ignoredups. A
value of erasedups causes all previous lines matching the cur‐
rent line to be removed from the history list before that line
is saved. Any value not in the above list is ignored. If
HISTCONTROL is unset, or does not include a valid value, all
lines read by the shell parser are saved on the history list,
subject to the value of HISTIGNORE. The second and subsequent
lines of a multi-line compound command are not tested, and are
added to the history regardless of the value of HISTCONTROL.
Exit without saving history kill -9 $$
this exits bash without saving the history. unlike explicitly disabling the history in some way, this works anywhere, and it works if you decide *after* issuing the command you don't want logged, that you don't want it logged
... $ ( or ${$} ) is the pid of the current bash instance
this also works perfectly in shells that don't have $ if you do something like
kill -9 `readlink /proc/self`