Commands
Difference between tail -f and tail -F
cp filename{,.bak}
Show disk usage of current dir or selected dir
Basically these two command are very similar, except tail -F do one more thing: the retry.
This is useful when you are tailing a web server log, e.g. apache log. When the the log file got rotated, thetail -F will continue to work since it will retry for the rotated file, while tail -f can't.
Make Backup filecp filename{,.bak}
Show disk usage of current dir or selected dir
du -s <dir>
Write to stdout
echo anything
Write to a file
echo anything > <path>
Append to a file
echo anything >> <path>
Update the modified time for a file
touch <path>
Quickly create an empty file
> <path>
Show differences between files
diff -r leftDir rightDir
Show files that differ without details
diff -r -q leftDir rightDir
Trace execution of a shell script
sh -x <fileName>
Monitor additions to a log file
tail -f <fileName>
Make a symbolic link
ln -s <path> <name>
List files in color
ls --color=tty
(Alias this to ls)
List a single column of names only
ls -1
List directories only
find -type d -maxdepth 1
(Alias this to lsd)
List files in order of modification time
ls -lrt
List files in order of size
ls -lrS
List all open files and sockets
lsof
Show the number of files in a directory
ls -1 | wc -l
Run a shell script so it changes the environment
source .bash_profile (or whatever script you changed)
Run a command relative to another root file system
chroot newroot command
Execute a shell script and echo the commands for debugging
sh -x yourScript
Low-level high speed copy
The dd command can copy between files or devices.
dd if=sourcePath of=destPath bs=1M
Using the optional bs=n option can speed up the copy. You can use
the suffix K, M, or G on numbers.
By adding the count option, you can write an exact number of fixed-size records.
For example, to destroy the partition table of a disk:
dd if=/dev/zero of=/dev/sdb3 bs=1K count=1
To display the status of a dd copy that's aready started, use this command
in another shell window:
kill -USR1 `pgrep '^dd$'`
This will cause dd to show a status message in it's original window
and continue with the copy operation.
Write a line to the syslog
logger This line is appended to /var/log/messages
logger -t MYTAG This line gets a MYTAG: prefix
Serial Number of VMware
dmidecode -t 1
To see the contents of a folder in human readable form
du -h --max-depth=1
Currently mounted filesystems in nice layout
mount | column -t
dmidecode -t 1
To see the contents of a folder in human readable form
du -h --max-depth=1
Currently mounted filesystems in nice layout
mount | column -t
Commands to find out Hardware details:
a) lshw: lshw (Hardware Lister) is a small tool to provide detailed information on the hardware configuration of the machine. It can report exact memory configuration, firmware version, mainboard configuration, CPU version and speed, cache configuration, bus speed, etc. on DMI-capable x86 or EFI (IA-64) systems and on some PowerPC machines.
b) Dmidecode: reports information about your system's hardware as described in your system BIOS according to the SMBIOS/DMI standard (see a sample output). This information typically includes system manufacturer, model name, serial number, BIOS version, asset tag as well as a lot of other details of varying level of interest and reliability depending on the manufacturer. This will often include usage status for the CPU sockets, expansion slots (e.g. AGP, PCI, ISA) and memory module slots, and the list of I/O ports (e.g. serial, parallel, USB). http://www.nongnu.org/dmidecode/
c) lspci is a utility for displaying information about all PCI buses in the system and all devices connected to them.
lspci -tv: Tree like Structure + Verbose
lspci -tv: Tree like Structure + Verbose
d) lsmod shows information about all loaded modules.The format is name, size, use count, list of referring modules. The information displayed is identical to that available from /proc/modules.
e) cat /etc/sysconfig/hwconf | less
f) dmesg is used to examine or control the kernel ring buffer and for hardware details too.
The program helps users to print out their bootup messages. Instead of copying the messages by hand, the user need only:
dmesg > boot.messages
and mail the boot.messages file to whoever can debug their problem.
g) lsdev - display information about installed hardware.
h) cat/proc/options.....
2) ls -ltr: Lists according to last created Item.
3) ls -lta: Lists parent directory and present directory.
4) ntsysv : Lists services settings.
5) lokkit: Lists firewall configuration.
6) lsof -i : Lists the open files associated with current ports.
7) find / -type f -mmin 10 ( Here f= normal files, -mmin 10= finding files modified less then 10 min)
3) ls -lta: Lists parent directory and present directory.
4) ntsysv : Lists services settings.
5) lokkit: Lists firewall configuration.
6) lsof -i : Lists the open files associated with current ports.
7) find / -type f -mmin 10 ( Here f= normal files, -mmin 10= finding files modified less then 10 min)
9) sysreport or sysreport -normp
$ uname -a
Linux box 2.4.10-4GB #1 Fri Sep 28 17:19:49 GMT 2001 i686 unknown
The output from uname indicates that the operating system is Linux, its
(kernel) release is 2.4.10, version #1 Fri Sep 28 17:19:49 GMT 2001, 34
Getting started and the name of the machine you are using is box. The hardware being
used (i.e. the type of physical machine, as opposed to the operating system, which is software), is an i686.
$ uname -r -v
2.4.10-4GB #1 Fri Sep 28 17:19:49 GMT 2001
$ uname -v -r
2.4.10-4GB #1 Fri Sep 28 17:19:49 GMT 2001
$ uname -rv
2.4.10-4GB #1 Fri Sep 28 17:19:49 GMT 2001
$ uname -vr
2.4.10-4GB #1 Fri Sep 28 17:19:49 GMT 2001
Options -m (machine), -n (nodename), -r (release), -s (system name)
or -v (version) can be used to print out part of the information that -a
(all) supplies. With no argument, -s is assumed by default. You can
combine options, for instance to print out the release and version of your
system, and can do so in one of four ways.
1. What does 'ps'mean?
ps is the shortage for Process Status. The command should be used to display the currently running processes on Unix/Linux systems. If you know the 'Task-Manager' which pops up under Windows NT/2000/XP when you press CTRL+ALT+DEL then you have a clue what ps does under Unix/Linux. Ps can show you the running processes on your system in different ways. I will describe the basic ones you should know.2. Why is it good to know how the ps command works?
If you have a process which seems to hang (e.g. netscape navigator on some buggy websites) and you want to stop the process, then you can determine the process id of the process. Why do you need the process id? You can stop the process with the help of the 'kill' command. The kill command needs a process number otherwise it won't know to which process it should send the 'kill' signal. Other example. You have started a process and now your machines becomes slower and slower. You stop the process but your machine still gets slower and slower. Now it will be helpful if you can stop the process. In this case you also need its pid.Next example: You want to know what processes your friend just uses (you know he has an remote session open), then you can also use the ps command to find out which processes belong to him.
Communicating with Users
Communicate with the system’s users and let them know what is going on! All Systems Administrators have the maintenance window where we can finally get control and handle some offline tasks. This is just one example of a need to communicate with the systems’ users, if any are still logged in. The most common way to get information to the system users is to use the /etc/motd file. This file is displayed each time the user logs in. If users stay logged in for days at a time they will not see any new messages of the day. This is one reason why real-time communication is needed. The commands shown in Table allow communication to, or between, users who are currently logged in the system.
3. Some examples for the ps command
ps -f Full listing of the user’s currently running processes
ps -ef Full listing of all processes, except kernel processes
ps -A All processes including kernel processes
ps -Kf Full listing of kernel processes
ps auxw Wide listing sorted by percentage of CPU usage, %CPU
Executing the ps command
just enter 'ps' at the prompt:$ ps
PID TTY TIME CMD
3511 pts/1 00:00:00 bash
3514 pts/1 00:00:00 ps
3.2. Displaying all processes owned by a specific user
$ ps ux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
heyne 691 0.0 2.4 19272 9576 ? S 13:35 0:00 kdeinit: kded
heyne 700 0.1 1.0 5880 3944 ? S 13:35 0:01 artsd -F 10 -S 40
heyne 710 0.0 2.8 21876 11072 ? S 13:35 0:00 kdeinit: knotify
heyne 711 0.0 0.0 1344 352 ? S 13:35 0:00 kwrapper ksmserve
heyne 713 0.0 2.4 18900 9304 ? S 13:35 0:00 kdeinit: ksmserve
heyne 714 0.0 2.9 21548 11528 ? S 13:35 0:00 kdeinit: kwin -se
heyne 715 0.3 4.8 31096 18820 ? S 13:35 0:03 /usr/lib/mozilla/
heyne 719 0.1 3.5 22548 13680 ? S 13:35 0:01 kdeinit: kdesktop
heyne 721 0.5 3.6 23904 14028 ? S 13:35 0:05 kdeinit: kicker
heyne 722 0.0 2.0 18504 7824 ? S 13:35 0:00 kdeinit: kio_file
heyne 723 0.0 4.8 31096 18820 ? S 13:36 0:00 /usr/lib/mozilla/
heyne 724 0.0 4.8 31096 18820 ? S 13:36 0:00 /usr/lib/mozilla/
heyne 725 0.0 4.8 31096 18820 ? S 13:36 0:00 /usr/lib/mozilla/
heyne 729 0.0 2.4 19408 9404 ? S 13:36 0:00 kdeinit: klaptopd
heyne 730 0.0 2.3 17044 9152 ? S 13:36 0:00 kteatime -session
heyne 731 0.0 3.0 21236 11848 ? S 13:36 0:00 kdeinit: kmix -se
heyne 735 0.0 4.8 31096 18820 ? S 13:36 0:00 /usr/lib/mozilla/
heyne 736 0.0 2.7 20492 10600 ? S 13:36 0:00 korgac --miniicon
heyne 745 0.0 2.4 19232 9528 ? S 13:36 0:00 kalarmd --login
heyne 753 0.0 0.3 2108 1160 pts/0 S 13:36 0:00 bash
heyne 787 0.7 1.7 9520 6784 ? S 13:50 0:00 emacs
heyne 789 0.2 0.3 2112 1164 pts/1 S 13:51 0:00 bash
heyne 794 0.0 0.4 3560 1576 pts/1 R 13:51 0:00 ps ux
You can also use the syntax "ps U username". In my case I use ps U heyne. If you use this syntax you get a result like the following:
PID TTY STAT TIME COMMAND
721 ? S 0:08 kdeinit: kicker
722 ? S 0:00 kdeinit: kio_file file /tmp/ksocket-heyne/klauncherx8
723 ? S 0:00 /usr/lib/mozilla/mozilla-bin
724 ? S 0:00 /usr/lib/mozilla/mozilla-bin
725 ? S 0:00 /usr/lib/mozilla/mozilla-bin
729 ? S 0:00 kdeinit: klaptopdaemon -session 11c0a8021400010381450
730 ? S 0:00 kteatime -session 11c0a802140001038168018000001282500
731 ? S 0:00 kdeinit: kmix -session 11c0a8021400010368648780000000
735 ? S 0:00 /usr/lib/mozilla/mozilla-bin
736 ? S 0:00 korgac --miniicon korganizer
745 ? S 0:00 kalarmd --login
753 pts/0 S 0:00 bash
787 ? S 0:01 emacs
789 pts/1 S 0:00 bash
796 ? S 0:07 kdeinit: konqueror --silent
800 ? S 0:00 kdeinit: kio_uiserver
801 ? S 0:02 xmms /files/mp3/00's/Badly Drawn Boy-About a Boy-03-S
802 ? S 0:00 xmms /files/mp3/00's/Badly Drawn Boy-About a Boy-03-S
803 ? S 0:00 xmms /files/mp3/00's/Badly Drawn Boy-About a Boy-03-S
804 ? S 0:00 xmms /files/mp3/00's/Badly Drawn Boy-About a Boy-03-S
837 ? S 0:00 xmms /files/mp3/00's/Badly Drawn Boy-About a Boy-03-S
838 ? S 0:00 xmms /files/mp3/00's/Badly Drawn Boy-About a Boy-03-S
860 pts/1 R 0:00 ps U heyne
As you can see, the ps command can give you a lot of interesting information. If you for example want to know what your friend actually does, just replace your login name with her/his name and you see all processe belonging to her/him.
3.3. Own output format
If you are bored by the regular output, you could simply change the format. To do so use the formatting characters which are supported by the ps command.
If you execute the ps command with the 'o' parameter you can tell the ps command what you want to see:
e.g.
Odd display with AIX field descriptors:
Turning off PING reply:
Also, to enable the ping reply back, set the value to “0″ as shown below.
Step 1: Edit the sysctl.conf file and add the following line.
After the ping reply is disabled using one of the above method, when somebody tries to ping your machine they will end up waiting without getting a ping reply packet even when the machine is up and running.
If you execute the ps command with the 'o' parameter you can tell the ps command what you want to see:
e.g.
Odd display with AIX field descriptors:
$ ps -o "%u : %U : %p : %a"
RUSER : USER : PID : COMMAND
heyne : heyne : 3363 : bash
heyne : heyne : 3367 : ps -o %u : %U : %p : %a
- / - root directory
- ./ - current directory
- ./command_name - run a command in the current directory when the current directory is not on the path
- ../ - parent directory
- ~ - home directory
- $ - typical prompt when logged in as ordinary user
- # - typical prompt when logged in as root or superuser
- ! - repeat specified command
- !! - repeat previous command
- ^^ - repeat previous command with substitution
- & - run a program in background mode
- [Tab][Tab] - prints a list of all available commands. This is just an example of autocomplete with no restriction on the first letter.
- x[Tab][Tab] - prints a list of all available completions for a command, where the beginning is ``x''
- [Alt][Ctrl][F1] - switch to the first virtual text console
- [Alt][Ctrl][Fn] - switch to the nth virtual text console. Typically, there are six on a Linux PC system.
- [Alt][Ctrl][F7] - switch to the first GUI console, if there is one running. If the graphical console freezes, one can switch to a nongraphical console, kill the process that is giving problems, and switch back to the graphical console using this shortcut.
- [ArrowUp] - scroll through the command history (in bash)
- [Shift][PageUp] - scroll terminal output up. This also works at the login prompt, so you can scroll through your boot messages.
- [Shift][PageDown] - scroll terminal output down
- [Ctrl][Alt][+] - switch to next X server resolution (if the server is set up for more than one resolution)
- [Ctrl][Alt][-] - change to previous X server resolution
- [Ctrl][Alt][BkSpc] - kill the current X server. Used when normal exit is not possible.
- [Ctrl][Alt][Del] - shut down the system and reboot
- [Ctrl]c - kill the current process
- [Ctrl]d - logout from the current terminal
- [Ctrl]s - stop transfer to current terminal
- [Ctrl]q - resume transfer to current terminal. This should be tried if the terminal stops responding.
- [Ctrl]z - send current process to the background
- reset - restore a terminal to its default settings
- [Leftmousebutton] - Hold down left mouse button and drag to highlight text. Releasing the button copies the region to the text buffer under X and (if gpm is installed) in console mode.
- [Middlemousebutton] - Copies text from the text buffer and inserts it at the cursor location. With a two-button mouse, click on both buttons simultaneously. It is necessary for three-button emulation to be enabled, either under gpm or in XF86Config.
Turning off PING reply:
Disable ping reply Temporarily
You can temporarily disable the ping reply using the following method.# echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
Please note that this setting will be erased after the reboot. To disable ping reply permanently (even after the reboot), follow the step mentioned below.Also, to enable the ping reply back, set the value to “0″ as shown below.
# echo "0" > /proc/sys/net/ipv4/icmp_echo_ignore_all
Disable ping reply Permanently
You can permanently disable the ping reply using the following method.Step 1: Edit the sysctl.conf file and add the following line.
net.ipv4.icmp_echo_ignore_all = 1
Step 2: Execute sysctl -p to enforce this setting immediately.# sysctl -p
The above command loads the sysctl settings from the sysctl.conf file.After the ping reply is disabled using one of the above method, when somebody tries to ping your machine they will end up waiting without getting a ping reply packet even when the machine is up and running.
###
exportfs -a : Exports all shared directories from /etc/exports
exportfs -r : Revises the list of shared directories after you have changed /etc/exports
This sends the appropriate signals to the rpc.nfsd and rpc.mountd daemons to reread the /etc/exports file and update their internal tables
exportfs -u : Unexports all directories
exportfs -v : Display currently shared directories.
If you have an error in your /etc/exports file, it is reported when NFS starts up in syslog
Ctrl-G Display current line number.
gg Move to first line in file. {vim}
numG Move to line number num.
G Move to last line in file.
:num Move to line number num.
H Top line of screen (Home position).
M Middle line of screen.
L Last line of screen.
CTRL + C Terminate current program
CTRL + Z Suspend current program
CTRL + D Exit the current shell
Tab Command/file auto-completion
Home Go to the beginning of the command line
End Go to the end of the command line
CTRL + L Clear the screen
Backspace Deletes text behind the cursor
ATL + Backspace Delete entire word behind the cursor
Delete Delete text in front of the cursor
CTRL + R Search command history
Up Arrow Cycle backward through command history
Down Arrow Cycle forward through command history
Left Arrow Move the cursor left one character
Right Arrow Move the cursor right one character
ALT + B Move the cursor back one word
ALT + F Move the cursor forward one word
CTRL + U Cut all text before the cursor
CTRL + K Cut all text after the cursor
ALT + D Cut the currently selected word
CTRL + Y Paste previously cut text
CTRL + _ (Underscore) Undo changes typed on the command line
CTRL + T Transpose the previous two characters on the command line
ALT + T Transpose the previous two words on the command line
ATL + L Convert word to lowercase
ATL + U Convert word to uppercase
| C-f | Move forward a character |
| C-b | Move backward a character |
| C-n | Move to next line |
| C-p | Move to previous line |
| C-a | Move to beginning of line |
| C-e | Move to end of line |
Linux Shortcuts for Shell Commands :
- Ctrl + D : exit a terminal, same as typing `exit`
- Ctrl + L : clears the screen, same as `clear`
- Ctrl + C : breaks/cancels an ongoing operation
- Ctrl + Z : pauses (stops) an ongoing operation. Type `fg` (foreground) to resume it or `bg` (background) to continue the process in the background
- Ctrl + Alt + Del : shuts down computer
Other bash Shell shortcuts:
Bash Shell shortcuts for Moving backward Forward :
- Ctrl + A : Go to the beginning of the line you are currently typing on
- Ctrl + E : Go to the end of the line you are currently typing on
- Ctrl + U : Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
- Ctrl + W : Delete the word before the cursor.
- Ctrl + K : Clear the line after the cursor.
- Ctrl + T : Swap the last two characters before the cursor.
- Esc + T : Swap the last two words before the cursor.
- Alt + F : Move cursor forward one word on the current line.
- Alt + B : Move cursor backward one word on the current line.
History related bash shell shortcuts:
- Ctrl + R : Let’s you search through previously used commands.
- Alt + < : Move to the first line in the history.
- Alt + > : Move to the last line in the history.
Other bash shell shortcuts:
- Ctrl + H : Same as backspace.
- Tab : Auto:complete files and folder names.
- Ctrl + Y : to paste it (as in delete and copy) all text in front of the cursor.
- Alt + ? : Show current completion list.
- Alt + * : Insert all possible completions.
- Alt + / : Attempt to complete filename.
- Alt + c : Capitalize the word.
- Alt + l : Make word lowercase.
- Alt + r : Recall command.
Comments
Post a Comment