Useful Linux commands

This post mentions some useful Linux commands.

File System Disk Space

Command to report file system disk space usage

df -h

option -h causes the sizes to be printed in human-readable format.

Tested on Oracle Linux Server release 6.3, Kernel: Linux 2.6.39-200.24.1.el6uek.x86_64

Command to report the space a particular directory is occupying

du -sh <dir>

option -s means display only a total for each directory argument

option -h means display the sizes in human-readable format

Tested on Oracle Linux Server release 6.3, Kernel: Linux 2.6.39-200.24.1.el6uek.x86_64

Command to report the space occupied by the sub-directories of the current directory

du --max-depth=1 -h

option –max-depth=1 means consider only those files and sub-directories which are 1 level below the current directory.

option -h means display the sizes in human-readable format

Tested on Kernel: Linux 2.6.32-279.el6.x86_64

OS information

Display information about the kernel of the OS

uname -rs

option -s displays the kernel name

option -r displays the kernel release

Tested on Oracle Linux Server release 6.3, Kernel: Linux 2.6.39-200.24.1.el6uek.x86_64

Display the version of the OS

cat /proc/version

Tested on Oracle Linux Server release 6.3, Kernel: Linux 2.6.39-200.24.1.el6uek.x86_64

System information

Print system information

uname -a

Tested on Oracle Linux Server release 6.3, Kernel: Linux 2.6.39-200.24.1.el6uek.x86_64

Print CPU information

cat /proc/cpuinfo

Tested on Linux version 2.6.32-279.5.2.el6.x86_64

Print CPU architecture information

lscpu

Tested on Linux version 2.6.32-279.5.2.el6.x86_64

Print Memory information

cat /proc/meminfo

Tested on Linux version 2.6.32-279.5.2.el6.x86_64

Symbolic links

For each file or directory in <source dir> create a symbolic link in <target dir>

cd <target dir>;
for i in <source dir>/*
do
t=${i##*/}
ln -s "$i" "${t}"
done

Tested on Oracle Linux Server release 6.3, Kernel: Linux 2.6.39-200.24.1.el6uek.x86_64

Compressed files

Display contents of a compressed file in an archive on the console

unzip -p <archive name> <compressed file name>

Example: unzip -p MyWebModule.war META-INF/MANIFEST.MF

option -p extracts the  files to pipe (stdout)

Tested on Oracle Linux Server release 6.3, Kernel: Linux 2.6.39-200.24.1.el6uek.x86_64

Tar multitple directories recursively

tar czvf <archive name> dir1 dir2 .. dirN

Example: tar czvf mytar.tar.gz dir1 dir2 .. dirN

Tested on Linux version 2.6.32-279.5.2.el6.x86_64

uname -a

Advertisements
This entry was posted in Linux and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s