Command Line
Command Line Tools
How to identify empty files or directories in Linux or UNIX
Feb 14th
The “find” command supports an option “-empty” to find files with zero size and directories which have no files and sub-directories.
The following command finds empty directories:
[neo@techpulp ~]# find . -empty -type d ./Documents/External ./Music/jazz ./Templates ./TestDir [neo@techpulp ~]#
The following command finds files with zero size:
[neo@techpulp ~]# find . -empty -type f ./Documents/draft1.doc ./Documents/testone.txt ./Music/download/u-and-me.mp3 [neo@techpulp ~]#
Similarly you can get the list of empty files and directories together with the following example:
[neo@techpulp ~]# find . -empty ./Documents/External ./Documents/draft1.doc ./Documents/testone.txt ./Music/download/u-and-me.mp3 ./Music/jazz ./Templates ./TestDir [neo@techpulp ~]#
If you want to clean up all empty files and directories recursively, you can use “xargs” command as shown below.
[neo@techpulp More >
How to monitor all processes in a Linux/UNIX system
Jan 29th
The Linux system provides a command called “top” which provides dynamic real-time view of running processes, memory status, cpu usage and other system information. This command is very easy to use and it updates the display automatically and user just needs to keep the command open. Then user needs to press the key “q” to close the display.
Here is the output of “top” command look like.
Tasks: 179 total, 1 running, 178 sleeping, 0 stopped, 0 zombie Cpu(s): 7.2%us, 2.6%sy, 0.0%ni, 88.5%id, 1.5%wa, 0.1%hi, 0.0%si, 0.0%st Mem: 2007980k total, 1046836k used, 961144k free, 55852k buffers Swap: 803208k total, 0k used, 803208k More >
How to see last login records of a user in Linux
Jan 29th
The Linux system stores login attempts of all users in a file called “wtmp“. Typically this file will be located in “/var/log” directory. The Linux command line utility “last” can be used to list the currently logged in users as well as their previous logins. The plain usage of the command without any arguments displays information about all users of the system.
[nick@techpulp ~]# last nick pts/4 :0 Thu Jan 29 21:59 still logged in neo pts/3 :0 Thu Jan 29 21:59 still logged in reboot system boot 2.6.10.5-1.fc2 Thu Jan 1 17:39 (01:38) liz pts/3 :0 Thu Jan 1 16:39 More >
How to list hidden files in Linux/UNIX
Jan 27th
Any hidden file or directory in UNIX/Linux systems start with period (.) character. The standard usage of “ls” skips the hidden files and directories from display. However if you would like to view hidden ones as well, the “ls” command supports “-a” option for it.
[neo@techpulp ~]# ls -a . changes.txt .fonts.conf .ICEauthority Music .. .bash_history Documents ginger.js .local .bash_profile Download .gpg-agent-info .macromedia Public .bashrc .esd_auth .gstreamer-0.10 Misc .pulse [neo@techpulp ~]#
In the above output, all files starting with period (.) characters are hidden files expect “.” and “..” entries. They are special files and represent current directory and parent directory respectively. You More >
How to determine type of a file in Linux
Jan 23rd
The command “file” tells you the file type and format. It maintains loads of magics in its database to identify the type of a file. If it can’t determine the file type, it will display whether it is an ASCII file or a binary file.
Here are few examples:
[neo@techpulp ~]# file /bin/bash /bin/bash: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped [neo@techpulp ~]# [neo@techpulp ~]# file Videos/Animals/leopard.flash Videos/Animals/leopard.flash: Macromedia Flash Video [neo@techpulp ~]# [neo@techpulp ~]# file MyDocs.zip MyDocs.zip: Zip archive data, at least v1.0 to extract [neo@techpulp ~]# file mantis-1.1.6-1.fc10.noarch.rpm mantis-1.1.6-1.fc10.noarch.rpm: RPM v3 bin mantis-1.1.6-1.fc10 More >
How to find how much disk space a directory is consuming in Linux
Jan 23rd
The Linux command line utility “du” (disk usage) tells you how much space a file or a directory is taking on the disk. Just run the command against a file or a directory. If a directory is specified it determines disk space used by all files and sub directories recursively. By default it displays number in KB (kilo bytes) and the option “-h” makes it show the sizes in human-readable format.
[neo@techpulp ~]# du -h Videos/ 59M Videos/Animals 4.0K Videos/Funny 59M Videos/ [neo@techpulp ~]#
You might be wondering what is the use of “du” command against a single file as “ls -l” on More >
How to log all that is displayed in my console to a file
Dec 8th
It is difficult to keep track of all that is printed in the console session especially if you are debugging a program with lots of debug messages. In such cases, you can use “script” command which spawns a new shell and all the activity on that shell is logged to a file until the shell is closed using “exit” command. By default, the “script” command stores the log in a file “typescript” which is stored in the same directory where the “script” command is run. Once you close the shell newly spawed by “script” command you will go back to More >
How to get a list of disk partitions and their file system types in Linux
Dec 6th
The “fdisk” command can be used to see disk geometry, partitions, size of each partition and their file system ID etc. The following shows the usage. This command requires super user privileges to run.
[root@neo neo]# fdisk -l Disk /dev/sda: 120.0 GB, 120034123776 bytes 255 heads, 63 sectors/track, 14593 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x282d282d Device Boot Start End Blocks Id System /dev/sda1 1 1657 13309821 83 Linux /dev/sda2 * 1658 5913 34186320 7 HPFS/NTFS /dev/sda3 5914 8159 18040995 83 Linux /dev/sda4 8160 14593 51681105 5 Extended /dev/sda5 8160 13145 40050013+ 83 Linux More >


Recent Comments