0% found this document useful (0 votes)
509 views15 pages

UNIX Assignments: 2: 1. List All The Files and Sub Directories of The Directory /bin

The document contains instructions for various UNIX commands performed on a system by the user himanshu. Some key points: 1. Various commands like ls, cat, cp, mv etc are used to list, create, copy, rename and delete files and directories in different locations on the system. 2. A directory structure is created under the home directory with subdirectories for system, hardware, software etc. and files are created under various subdirectories. 3. Commands like ls, pwd are used to list contents of directories and print the current working directory from different locations in the filesystem. 4. Special characters and patterns are used with ls command to filter files based on name, extension etc.

Uploaded by

Himanshu Rustagi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
509 views15 pages

UNIX Assignments: 2: 1. List All The Files and Sub Directories of The Directory /bin

The document contains instructions for various UNIX commands performed on a system by the user himanshu. Some key points: 1. Various commands like ls, cat, cp, mv etc are used to list, create, copy, rename and delete files and directories in different locations on the system. 2. A directory structure is created under the home directory with subdirectories for system, hardware, software etc. and files are created under various subdirectories. 3. Commands like ls, pwd are used to list contents of directories and print the current working directory from different locations in the filesystem. 4. Special characters and patterns are used with ls command to filter files based on name, extension etc.

Uploaded by

Himanshu Rustagi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

UNIX Assignments: 2

1. List all the files and sub directories of the directory /bin. himanshu@ubuntu:~$ ls /bin bash bunzip2 busybox bzcat bzcmp bzdiff bzegrep bzexe bzfgrep bzgrep bzip2 bzip2recover bzless bzmore dumpkeys echo ed egrep false mount mountpoint mt mt-gnu mv sh [Link] sleep static-sh stty su sync tailf tar tempfile touch true ulockmgr_server

fgconsole nano fgrep fuser nc [Link]

fusermount netcat grep gunzip gzexe gzip netstat

nisdomainname ntfs-3g [Link]

hostname

[Link] umount

cat chgrp chmod chown chvt cp cpio dash date

ip

[Link] uname open uncompress unicode_start vdir vmmouse_detect which ypdomainname zcat zcmp rbash zdiff zegrep zfgrep zforce zgrep zless zmore setfont znew

kbd_mode kill less lessecho lessfile lesskey lesspipe ln

openvt pidof ping ping6 plymouth ps

pwd

dbus-cleanup-sockets loadkeys dbus-daemon dbus-uuidgen dd df dir dmesg dnsdomainname ls lsmod mkdir mknod login

readlink

lowntfs-3g rm rmdir rnano run-parts sed

mktemp

domainname

more

setupcon

2. List all the files including hidden files in your current directory. himanshu@ubuntu:~$ ls -a . .. .gconfd .gnome2 Pictures play

.bash_history .bash_logout .bashrc .cache .compiz .config .dbus Desktop .dmrc Documents Downloads .esd_auth

.gnome2_private .[Link] .gstreamer-0.10 .profile .gtk-bookmarks Public .gvfs [Link] .[Link] [Link] [Link] .ICEauthority [Link] .local .mozilla .pulse .pulse-cookie .[Link] .sudo_as_admin_successful .swp system Templates .thumbnails Videos

[Link] Music .fontconfig .gconf .nautilus

.xsession-errors .[Link]

.[Link]

3. List all the files starting with letter r in your current directory. himanshu@ubuntu:~$ ls -f r* roshan .sh 4. List all the files having three characters in their names, from your current directory. himanshu@ubuntu:~$ ls ??? him:

his: 5. List all the files with extension .doc in your current directory. himanshu@ubuntu:~$ ls *.doc Linux [Link] Linux [Link] Linux [Link] 6. List all the files having the first letter of their name within the range l tos, from your current directory. himanshu@ubuntu:~$ ls [l-s]* Linux [Link] Linux [Link] roshan .sh Linux [Link] Linux [Link]

Music:

Pictures:

play:

Public:

system: hardware software 7. Create a file text1 and read its input from keyboard. himanshu@ubuntu:~$ cat > text1 hi i m himanshu doing mca rom dkes -scs ^C 8. Copy the contents of file text1 to another file text2. himanshu@ubuntu:~$ cp text1 text2 himanshu@ubuntu:~$ cat text2 hi i m himanshu doing mca rom dkes -scs 9. Append the contents of file text2 to file text1. himanshu@ubuntu:~$ cat >> text1 text2 himanshu@ubuntu:~$ cat text1 hi i m himanshu doing mca rom dkes -scs

hi i m himanshu doing mca rom dkes -scs 10. Count the number of files in the current directory. himanshu@ubuntu:~$ ls|wc -w 29 11. Display the output of command ls l to a file and on the output screen. himanshu@ubuntu:~$ ls|cat > text3|cat text3 Desktop Documents Downloads [Link] him [Link] his [Link] [Link] [Link] Linux [Link] Linux [Link]

Linux [Link] Linux [Link] Music Pictures play Public roshan .sh system Templates text1 text2 text3 Videos 12. From file text1 print all lines starting from 10th line. himanshu@ubuntu:~$ tail -n +10 text3 [Link] Linux [Link] Linux [Link]

Linux [Link] Linux [Link] Music Pictures Public roshan .sh system Templates text1 text2 text3 Videos himanshu@ubuntu:~$ 13. Find the number of users currently logged on to the system. himanshu@ubuntu:~$ who|wc -l 2 14. Delete all the files with their names starting with tmp. himanshu@ubuntu:~$ rm tmp*

rm: cannot remove `tmpe': Is a directory 15. List only the directories in your current directory himanshu@ubuntu:~$ ls -d .

Section 2:
1. Display your current working directory. himanshu@ubuntu:~$ pwd /home/himanshu 2. Create following directory structure under your Home directory (Note: Your home directory is where you login to.) SYSTEM (SUB DIRECTORY)

HARDWARE

(SUB-SUB DIRECTORY)

SOFTWARE

INPUT

OUTPUT

(SUB-SUB-SUB)

APPL

SYS OS LINKERS

MOUSE PRINTER ( FILES ) WORDSTAR SCANNER VDU (FILES ) LOTUS himanshu@ubuntu:~$ mkdir -p system/hardware/input himanshu@ubuntu:~$ mkdir -p system/hardware/output himanshu@ubuntu:~$ mkdir -p system/software/appl himanshu@ubuntu:~$ mkdir -p system/software/sys himanshu@ubuntu:~$ cd system/hardware/input himanshu@ubuntu:~/system/hardware/input$ cat > mouse i am mouse ^C

himanshu@ubuntu:~/system/hardware/input$ cat > scanner iam scanner ^C himanshu@ubuntu:~/system/hardware/input$ cd .. himanshu@ubuntu:~/system/hardware$ cd output himanshu@ubuntu:~/system/hardware/output$ cat > printer i am a printer ^C himanshu@ubuntu:~/system/hardware/output$ cat > vdu i am a vedio display unit ^C himanshu@ubuntu:~/system/hardware/output$ cd ../.. himanshu@ubuntu:~/system$ cd software/appl himanshu@ubuntu:~/system/software/appl$ cat > wordstar i am a wordstar ^C himanshu@ubuntu:~/system/software/appl$ cat > lotus i am a lotus ^C himanshu@ubuntu:~/system/software/appl$ cd .. himanshu@ubuntu:~/system/software$ cat > os i am an os ^C himanshu@ubuntu:~/system/software$

himanshu@ubuntu:~/system/software$ cat > linker i am a linker ^C himanshu@ubuntu:~/system/software$ 3. List detailed information about all the files and directories of Hardware directory while your current directory is still the home directory. himanshu@ubuntu:~$ ls -l system/hardware total 8 drwxr-xr-x 2 himanshu himanshu 4096 2012-10-08 20:59 input drwxr-xr-x 2 himanshu himanshu 4096 2012-10-08 21:01 output 4. Change your current directory to SYS and list the names of all files and subdirectories in the directory sub tree starting that starts from your home directory. himanshu@ubuntu:~$ cd system/software/sys himanshu@ubuntu:~/system/software/sys$ himanshu@ubuntu:~/system/software/sys$ ls ~ Desktop Documents Downloads [Link] his [Link] Linux [Link] Pictures Videos Linux [Link] play Linux [Link] Public Linux [Link] system Templates

[Link] [Link] him

[Link] Music

5. Copy the file SCANNER to directory SYSTEM while your current directory is APPL. himanshu@ubuntu:~/system/software/appl$ cp ~/system/hardware/input/scanner ~/system/[Link] himanshu@ubuntu:~/system/software/appl$ 6. Rename the file SCANNER to SCAN. himanshu@ubuntu:~/system/software/appl$ mv ~/system/hardware/input/scanner

~/system/hardware/input/scan 7. Read some text form Keyboard and append it to the file SCAN. himanshu@ubuntu:~/system/software/appl$ cat >> ~/system/hardware/input/scan now i am scan ^C himanshu@ubuntu:~/system/software/appl$ 8. Remove the directory sub tree starting from SYSTEM in one go. (Note: This command is potentially dangerous) himanshu@ubuntu:~$ rm -rf system

Section 3:
1. List the contents of ls command page wise. himanshu@ubuntu:~$ ls -l|more total 276 drwxr-xr-x 3 himanshu himanshu 4096 2012-10-03 18:04 Desktop drwxr-xr-x 2 himanshu himanshu 4096 2012-10-02 08:36 Documents drwxr-xr-x 2 himanshu himanshu 4096 2012-08-28 14:52 Downloads -rw-r--r-- 1 himanshu himanshu 179 2012-08-28 14:50 [Link] drwxr-xr-x 2 himanshu himanshu 4096 2012-10-08 20:20 him -rw-r--r-- 1 himanshu himanshu 17 2012-08-28 14:58 [Link]

drwxr-xr-x 2 himanshu himanshu 4096 2012-10-08 20:20 his -rw------- 1 himanshu himanshu 404 2012-09-29 21:07 [Link] -rw-r--r-- 1 himanshu himanshu 601 2012-09-29 20:40 [Link] -rw-r--r-- 1 himanshu himanshu 29583 2012-09-12 14:36 [Link] -rw-r--r-- 1 himanshu himanshu 6366 2012-10-07 21:57 Linux [Link] -rw-r--r-- 1 himanshu himanshu 56320 2012-09-25 10:14 Linux [Link] -rw-r--r-- 1 himanshu himanshu 57856 2012-09-25 10:15 Linux [Link] -rw-r--r-- 1 himanshu himanshu 59904 2012-09-25 10:16 Linux [Link]

drwxr-xr-x 2 himanshu himanshu 4096 2012-08-28 14:52 Music drwxr-xr-x 2 himanshu himanshu 4096 2012-08-28 14:52 Pictures drwxr-xr-x 2 himanshu himanshu 4096 2012-10-07 21:37 play drwxr-xr-x 2 himanshu himanshu 4096 2012-08-28 14:52 Public drwxr-xr-x 2 himanshu himanshu 4096 2012-08-28 14:52 Templates drwxr-xr-x 2 himanshu himanshu 4096 2012-08-28 14:52 Videos 2. Create a file FILE2 with some text in it. Increase the no. of hard links to the file FILE2 to 3 and check the inode number and link count for those names. himanshu@ubuntu:~$ cat >> file2 hlo i m himanshu how are you ^C himanshu@ubuntu:~$ ln file2 file22 himanshu@ubuntu:~$ ln file2 file21 himanshu@ubuntu:~$ ln file2 file23 himanshu@ubuntu:~$ ls -i file2* 418754 file2 418754 file21 418754 file22 418754 file23 himanshu@ubuntu:~$ ls -l file2* -rw-r--r-- 4 himanshu himanshu 29 2012-10-08 23:10 file2 -rw-r--r-- 4 himanshu himanshu 29 2012-10-08 23:10 file21 -rw-r--r-- 4 himanshu himanshu 29 2012-10-08 23:10 file22 -rw-r--r-- 4 himanshu himanshu 29 2012-10-08 23:10 file23 3. Using one single command, display the output of who and pwd commands. himanshu@ubuntu:~$ who;pwd

himanshu tty7 himanshu pts/0 himanshu pts/1 /home/himanshu

2012-10-08 23:03 (:0) 2012-10-08 23:04 (:0.0) 2012-10-08 23:13 (:0.0)

4. Find out whether the users with a patternitp9 in their names have logged in ? himanshu@ubuntu:~$ who|cut -d " " -f1|fgrep itp9 5. Find out whether a particular user itp9 has logged in ? [Link] n=`expr who|cut -d " " -f1|fgrep itp9|wc -l` if [ $n -ne 0]; then echo "no" else echo "yes" fi

You might also like