How to Manage System Time and File Types in Linux
Important Commands to Manage System Time and File Types in Linux
There are many commands to manage system time and files types in Linux. In Linux there are so many file types available such as,
Regular files &ndash In Regular files like text file, music file , archive file, image files, etc.
Device files &ndash In device file there are two files, block files refers storage devices. It read as blocks and the character files read as characters.
Link files &ndash To access files from anywhere on a Linux system using soft-links and hard-links.
In this tutorial we are going to see about the commands as follows.
To Determine the type of a file using “ file” command
Run the following command to determine the type of a file using “ file” command
[root@linuxhelp Desktop]# ls acl command ( f ) DIG-cmmd.odt file2.odt file5.odt file8.odt gig.tar AWK command ( f ) file10.odt file3.odt file6.odt file9.odt linux.odt cat cmd ( F ) file1.odt file4.odt file7.odt file.txt ll.odt [root@linuxhelp Desktop]# file linux.odt linux.odt: OpenDocument Text [root@linuxhelp Desktop]# file gig.tar gig.tar: bzip2 compressed data, block size = 900k [root@linuxhelp Desktop]# file /dev/sda5 /dev/sda5: block special
Suppose if you entered directory instead of file, then it mentions as a directory in the output.
[root@linuxhelp Desktop]# file " acl command( f )"
acl command ( f ): directory
To determine the file type using “ ls” and “ dir” commands
To display the type of a file, use ls -l command. In file permissions, 1st character shows the file type and other shows file permissions.
[root@linuxhelp Desktop]# ls -l
total 568
drwxr-xr-x. 2 root root 4096 Apr 2 05:32 acl command ( f )
drwxr-xr-x. 2 root root 4096 Apr 1 22:12 AWK command ( f )
drwxr-xr-x. 2 root root 4096 Apr 1 21:15 cat cmd ( F )
-rw-r--r--. 1 root root 28445 Apr 7 17:54 DIG-cmmd.odt
-rw-r--r--. 1 root root 45771 Apr 7 12:16 file10.odt
-rw-r--r--. 1 root root 43640 Apr 7 12:11 file1.odt
.
.
.
-rw-r--r--. 1 root root 12 Apr 7 12:01 file.txt
-rw-r--r-- 1 root root 27238 Apr 8 12:05 gig.tar
-rw-r--r--. 1 root root 32388 Apr 7 15:26 linux.odt
-rw-r--r--. 1 root root 11818 Apr 7 18:48 ll.odt
To display the type of a file, use dir -l command. In file permissions, 1st character shows the file type and other shows file permissions.
[root@linuxhelp Desktop]# dir -l
total 568
drwxr-xr-x. 2 root root 4096 Apr 2 05:32 acl command ( f )
drwxr-xr-x. 2 root root 4096 Apr 1 22:12 AWK command ( f )
drwxr-xr-x. 2 root root 4096 Apr 1 21:15 cat cmd ( F )
.
.
.
-rw-r--r-- 1 root root 27238 Apr 8 12:05 gig.tar
-rw-r--r--. 1 root root 32388 Apr 7 15:26 linux.odt
-rw-r--r--. 1 root root 11818 Apr 7 18:48 ll.odt
To display block and character files
In the below example, the ls -l command is used to display the block and the character files.
[root@linuxhelp Desktop]# ls -l /dev/sda5
3brw-rw---- 1 root disk 8, 5 Apr 8 11:29 /dev/sda5
In the below example, the dir -l command is used to display the block and the character files.
[root@linuxhelp Desktop]# dir -l /dev/sda5
brw-rw---- 1 root disk 8, 5 Apr 8 11:29 /dev/sda5
To display tar files using “ ls” and “ dir”
Execute the below commands to display tar files as shown in the example.
[root@linuxhelp Desktop]# ls -l gig.tar -rw-r--r-- 1 root root 27238 Apr 8 12:05 gig.tar [root@linuxhelp Desktop]# dir -l gig.tar -rw-r--r-- 1 root root 27238 Apr 8 12:05 gig.tar
To Count number of files and directories available in current working directory
Piping is used to make communication between ls, grep and wc commands. The below command will display how many files is available in present working directory.
[root@linuxhelp Desktop]# ls -l | grep ^- | wc -l
13
The below command will display how many directories available in current working directory.
[root@linuxhelp Desktop]# ls -l | grep ^d | wc -l
3
The following command will display how many link files available in current working directory file.
[root@linuxhelp songs]# ls -l | grep ^l | wc -l
1
The following command will shows how many blocks and characters available in /dev.
[root@linuxhelp Desktop]# ls -l /dev | grep ^b | wc -l 32 [root@linuxhelp Desktop]# ls -l /dev | grep ^c | wc -l 136
To find files in Linux
To find files in Linux, we use commands such as locate, find, whatis, which and whereis.
Locate command
The locate command is used to find files by their filename. The locate command is lightning fast because there is a background process that runs on your system that continuously finds new files and stores them in a database.
[root@linuxhelp Desktop]# locate sshd_config
/etc/ssh/sshd_config
/usr/share/man/man5/sshd_config.5.gz
Find command
The find command is a very useful and handy command to search for files from the command line. It can be used to find files based on various search criteria like permissions, user ownership, modification date/time, size, etc.
[root@linuxhelp Desktop]# find /etc -name httpd.conf
/etc/httpd/conf/httpd.conf
Whatis command
Whatis command is helpful to get brief information about Linux commands or functions.
[root@linuxhelp Desktop]# whatis squid squid (8) - proxy caching server [root@linuxhelp Desktop]# whatis touch touch (1) - change file timestamps touch (1p) - change file access and modification times [root@linuxhelp Desktop]# whatis uptime uptime (1) - Tell how long the system has been running
Which command
Which command is used to locate the full path of shell commands.
[root@linuxhelp Desktop]# which wc /usr/bin/wc [root@linuxhelp Desktop]# which du /usr/bin/du [root@linuxhelp Desktop]# which df /bin/df
whereis command
The command whereis is used to locate the binary, source code and man page for specified program or command.
[root@linuxhelp Desktop]# whereis ssh ssh: /usr/bin/ssh /etc/ssh /usr/share/man/man1/ssh.1.gz [root@linuxhelp Desktop]# whereis samba samba: /etc/samba /usr/lib64/samba
To manage your time in Linux
To manage time in your linux system, we use two ways i.e. system time managed by system clock and hardware time managed by hardware clock.
To use the date command as below, to view time, date and timezone of your system.
[root@linuxhelp Desktop]# date
Fri Apr 8 13:31:12 IST 2016
To modify the date and time on your own
[root@linuxhelp Desktop]# date -s " 14:00:15" Fri Apr 8 14:00:15 IST 2016 [root@linuxhelp Desktop]# date 040813302016 Fri Apr 8 13:30:00 IST 2016
Using cal command, we can view current date from a calendar
[root@linuxhelp Desktop]# cal April 2016 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
Using the hwclock command, we can view hardware clock time.
[root@linuxhelp Desktop]# hwclock
Fri 08 Apr 2016 01:36:27 PM IST -0.307962 seconds
Use the following command to set the hardware clock time.
[root@linuxhelp Desktop]# hwclock --set --date=" 04/08/2016 01:45:00"
[root@linuxhelp Desktop]# hwclock
Fri 08 Apr 2016 01:45:12 AM IST -0.189386 seconds
During the boot up process, the system time will reset hardware time. When the CMOS battery is weak, it displays the wrong hardware time.
To set system clock time using hardware clock time, to execute below command.
[root@linuxhelp Desktop]# hwclock --set --date=" 08/04/2016 01:45:00"
[root@linuxhelp Desktop]# hwclock
Thu 04 Aug 2016 01:45:12 AM IST -0.189386 seconds
To use the uptime command, you can view how long your Linux system has been working.
[root@linuxhelp Desktop]# uptime
13:35:55 up 21 min, 2 users, load average: 0.00, 0.02, 0.05
Comments ( 0 )
No comments available