• Categories
    Category
  • Categories
    Category
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial Comments FAQ Related Articles

Interesting Command Line Tips and Tricks in Linux

256

Interesting Command Line Tips and Tricks in Linux

In this article we will learn some new tips and tricks in the Linux commands.

History command

Using history command, we can check what are the commands did in past.

[root@linuxhelp ~]# history
    4  vim /etc/sysconfig/network
    5  cd
    6  fdisk -l
    7  fdisk /dev/sdb
    8  fdisk -l
    9  fdisk -l /dev/sdb
   10  fdisk -l /dev/sda
   11  fdisk /dev/sda
   12  fdisk -l /dev/sda
   13  fdisk -s /dev/sda2
   14  fdisk -l /dev/sda
   15  fdisk /dev/sda
   16  cd
   .  .  .   .  .
   .  .  .   .  .
   .  .  .   .  .
   990  dd if=/dev/zero of=/tmp/output.img bs=8k count=256k conv=fdatasync  rm -rf /tmp/output.img
  991  du -hsx * | sort -rh | head -6
  992  stat fedora.iso
  993  cd Desktop/
  994  stat Screenshot222.png
  995  pwd
  996  cd /home/jagannath/
  997  cd Desktop/
  998  pwd
  999  stat Screenshot222.png
 1000  man $(ls /bin | shuf | head -1)
 1001  cd
 1002  clear
 1003  history

If you need the history with time stamp, then execute the below command.

[root@linuxhelp ~]# HISTTIMEFORMAT=" %d/%m/%y %T " 
[root@linuxhelp ~]# history
    6  25/03/16 07:19:52 fdisk -l
    7  25/03/16 07:19:52 fdisk /dev/sdb
    8  25/03/16 07:19:52 fdisk -l
    9  25/03/16 07:19:52 fdisk -l /dev/sdb
   10  25/03/16 07:19:52 fdisk -l /dev/sda
   11  25/03/16 07:19:52 fdisk /dev/sda
   12  25/03/16 07:19:52 fdisk -l /dev/sda
   13  25/03/16 07:19:52 fdisk -s /dev/sda2
   14  25/03/16 07:19:52 fdisk -l /dev/sda
   15  25/03/16 07:19:52 fdisk /dev/sda
   16  25/03/16 07:19:52 cd
   17  25/03/16 07:19:52 vim /etc/sysconfig/network
   .  .  .   .  .
   .  .  .   .  .
   .  .  .   .  .
   990  25/03/16 03:30:35 dd if=/dev/zero of=/tmp/output.img bs=8k count=256k conv=fdatasync  rm -rf /tmp/output.img
  991  25/03/16 03:32:50 du -hsx * | sort -rh | head -6
  992  25/03/16 03:37:46 stat fedora.iso
  993  25/03/16 03:38:33 cd Desktop/
  994  25/03/16 03:40:14 stat Screenshot222.png
  995  25/03/16 03:40:32 pwd
  996  25/03/16 03:40:42 cd /home/jagannath/
  997  25/03/16 03:40:55 cd Desktop/
  998  25/03/16 03:40:58 pwd
  999  25/03/16 03:41:08 stat Screenshot222.png
 1000  25/03/16 03:44:23 man $(ls /bin | shuf | head -1)
 1001  25/03/16 07:19:55 cd
 1002  25/03/16 07:19:58 clear
 1003  25/03/16 07:20:13 history
 1004  25/03/16 07:22:59 HISTTIMEFORMAT=" %d/%m/%y %T " 
 1005  25/03/16 07:23:08 history

Add the below line to ~/.bashrc, If you need to append this change permanently.

[root@linuxhelp ~]# export HISTTIMEFORMAT=" %d/%m/%y %T " 
[root@linuxhelp ~]# source ~/.bashrc

Explanation of commands are,

History denotes as GNU History Library.
HISTIMEFORMAT is the Environmental Variable.
%d denotes as Day.
%m denotes as Month.
%y denotes as Year.
%T denotes the Time Stamp.
source represents in short send the contents of file to shell.
.bashrc denotes a shell script, if it started interactively then BASH start to run.

dd command

Using dd command, we can check disk write speed.

[root@linuxhelp ~]# dd if=/dev/zero of=/tmp/output.img bs=8k count=256k conv=fdatasync  rm -rf /tmp/output.img
262144+0 records in
262144+0 records out
2147483648 bytes (2.1 GB) copied, 20.7229 s, 104 MB/s

Explanation of commands are,
dd mentions Convert and Copy a file.
if=/dev/zero denotes Read the file and not stdin.
of=/tmp/output.img command used to Write to file and not stdout.
bs used to Read and Write maximum upto M bytes, at one time.
count used to Copy N input block.
conv is the command line used to Convert the file as per comma separated symbol list.
rm used to Removes files and folder.
-rf used to (-r) removes directories and contents recursively and (-f) Force the removal without prompt.

du command

Using du command, we can check first six files that occupying more space in your system.

[root@linuxhelp ~]# du -hsx * | sort -rh | head -6
287M    gitlab-7.7.1_omnibus.5.4.1.ci-1.el6.x86_64.rpm
11M    j
11M    home
4.4M    gitlab-workhorse
3.3M    mantisbt-1.2.19.zip
116K    install.log

Explanation of commands are,
du needs to Estimate file space usages.
-hsx used to (-h) Human Readable Format, (-s) Summaries Output, (-x) One File Format, skip directories on other file format.
sort command is used to Sort text file lines.
-rh used to (-r) Reverse the result of comparison, (-h) for compare human readable format.
head is the command used to output first n lines of file.

stat command

Using stat command, we can get the statistics related to a file.

stat filename_ext (viz., stat abc.pdf)

[root@linuxhelp ~]# cd /tmp
[root@linuxhelp tmp]# stat csf.tgz
File: `csf.tgz' 
Size: 688544 Blocks: 1352 IO Block: 4096 regular file
Device: 802h/2050d Inode: 693045 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2016-03-17 10:09:01.858006913 +0530
Modify: 2016-02-25 23:23:17.000000000 +0530
Change: 2016-03-17 09:59:49.626007416 +0530

Another Example:

[root@linuxhelp tmp]# stat autoinstaller3.log
File: `autoinstaller3.log' 
Size: 12020 Blocks: 24 IO Block: 4096 regular file
Device: 802h/2050d Inode: 656910 Links: 1
Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2016-03-19 07:45:51.854643390 +0530
Modify: 2016-03-19 08:35:23.938004452 +0530
Change: 2016-03-19 08:35:23.938004452 +0530

man command

Using man command, we can generate random man pages and that helps to learn new about linux.

[root@linuxhelp tmp]# man $(ls /bin | shuf | head -1)
OSTNAME(1) Linux Programmer’ s Manual HOSTNAME(1)

NAME
hostname - show or set the system’ s host name
domainname - show or set the system’ s NIS/YP domain name
dnsdomainname - show the system’ s DNS domain name
nisdomainname - show or set system’ s NIS/YP domain name
ypdomainname - show or set the system’ s NIS/YP domain name

SYNOPSIS
hostname [-v] [-a] [--alias] [-d] [--domain] [-f] [--fqdn] [-A] [--all-
fqdns] [-i] [--ip-address] [-I] [--all-ip-addresses] [--long] [-s]
[--short] [-y] [--yp] [--nis]

hostname [-v] [-F filename] [--file filename] [hostname]

domainname [-v] [-F filename] [--file filename] [name]

nodename [-v] [-F filename] [--file filename] [name]

hostname [-v] [-h] [--help] [-V] [--version]

dnsdomainname [-v]
nisdomainname [-v]
ypdomainname [-v]

:q----> to quit

Explanation of commands are,

man command is used to display Linux Man pages.
ls used to Linux Listing Commands.
/bin denotes System Binary file Location.
shuf used to Generate Random Permutation.
head used to Output first n line of file.

Tags:
matthew
Author: 

Comments ( 0 )

No comments available

Add a comment

Frequently asked questions ( 5 )

Q

What is the command to view the statics of the log?

A

The command used to view the statics of the log is
Syntax: "stat autoinstaller3.log"

Q

How to execute the history with timestamp command?

A

By using this command we can get
HISTTIMEFORMAT=" %d/%m/%y %T "

Q

How can we generate random man pages?

A

By using this command we can get
man $(ls /bin | shuf | head -1)

Q

How to check the first six files occupying space in your system?

A

By using this command we can get
du -hsx * | sort -rh | head -6

Q

What is the command to view the statics of the log?

A

The command used to view the statics of the log is
Syntax: "stat autoinstaller3.log"

Related Tutorials in Interesting Command Line Tips and Tricks in Linux

Related Tutorials in Interesting Command Line Tips and Tricks in Linux

FFmpeg Commands in Linux with Examples
FFmpeg Commands in Linux with Examples
Apr 4, 2016
Basic Linux Command Line Tricks
Basic Linux Command Line Tricks
Apr 20, 2016
Useful commands to manage Desktop and Server in Linux - Part 1
Useful commands to manage Desktop and Server in Linux - Part 1
Apr 27, 2016
Useful commands to manage Desktop and Server in Linux - Part 2
Useful commands to manage Desktop and Server in Linux - Part 2
Apr 27, 2016
How to use mkdir, tar and kill commands efficiently in Linux
How to use mkdir, tar and kill commands efficiently in Linux
Apr 19, 2016
Interesting Command Line Tips and Tricks in Linux
Interesting Command Line Tips and Tricks in Linux
Apr 5, 2016
How to run Linux commands every X seconds
How to run Linux commands every X seconds
Mar 25, 2016

Related Forums in Interesting Command Line Tips and Tricks in Linux

Related Forums in Interesting Command Line Tips and Tricks in Linux

CentOS
isaiah class=
pidstat no found
May 28, 2018
Basic Commands
FerTah class=
Command sort or uniq
Apr 10, 2019
Windows
Aditya class=
Net view usage in Windows 10
Jul 31, 2019
Basic Commands
gibbson class=
How to install locate command
Aug 25, 2018
Basic Commands
yousuf class=
How to check history command with time
Aug 25, 2018
Basic Commands
raven class=
Basic Commans are not working
Dec 29, 2017
CentOS
muhammad class=
list files on created time
Jun 12, 2018
Basic Commands
elijah class=
How to List only Directories from the Current Location in Linux
Dec 18, 2019
Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Gibbson ?
How do i run both nginx and apache in same instance on centos

Hi...,

my server is based centos operating system and my webserver is already running on Apache.... i need to run both apache and nginx on same instance ... please help me to implement this concept...

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.