CH 05 Searching and Manipulating Files
CH 05 Searching and Manipulating Files
more
more – To display file contents one screen at a
time
$more file1
[SpaceBar] – To display the next screen
[Enter] - advance 1 line
q - quit
more
[alex@server1 ~]$ more /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
less
less – It is similar to more , but which allows
backward movement in the file as well as forward
movement.
$less file1
[SpaceBar] – To display the next screen
[Enter] - advance 1 line
b - go backwards
q - quit
less
[alex@server1 ~]$ less /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sb
head
head – To display lines from the beginning of a
file ,the default is 10 lines.
$head /etc/passwd
displays the first 10 lines of /etc/passwd
$head -5 /etc/passwd
displays the first 5 lines of /etc/passwd
head
[alex@server1 ~]$ head -5 /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
[alex@server1 ~]$
tail
tail – To display lines from the end of a file, the
default is 10 lines.
$tail /etc/passwd
displays the last 10 lines of /etc/passwd
$tail -5 /etc/passwd
displays the last 5 lines of /etc/passwd
tail
[alex@server1 ~]$ tail -5 /etc/passwd
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
alex:x:500:500:alex:/home/alex:/bin/bash
user1:x:501:501::/home/user1:/bin/bash
user2:x:502:502::/home/user2:/bin/bash
user3:x:503:503::/home/user3:/bin/bash
[alex@server1 ~]$
grep
[alex@Server1 ~]$
Redirecting output
[alex@Server1 ~]$ grep HP computers >list1
[alex@Server1 ~]$ cat list1
HP Laptop
HP Server
HP Printer
[alex@Server1 ~]$
Redirecting output
[alex@Server1 ~]$ grep Dell computers >>list1
[alex@Server1 ~]$ cat list1
HP Laptop
HP Server
HP Printer
Dell Laptop
Dell Server
[alex@Server1 ~]$
Pipes
./September/list_SepFoods
./October/list_Octfoods
If no path is given, find looks in the current directory and its
subdirectories
/etc/passwd
/etc/pam.d/passwd
[alex@server1 ~]$
find
Find is an excellent tool for generating reports on basic
information regarding files or directories but what if you
want more than just reports?
Execute option
$ sort file