Sei sulla pagina 1di 2

Working with files

1. List the directories in /bin.

student@mca25:~$ ls -d /bin/*
/bin/bash /bin/ed /bin/lsblk /bin/open /bin/systemd-
inhibit
/bin/bunzip2 /bin/efibootmgr /bin/lsmod /bin/openvt
/bin/systemd-machine-id-setup
/bin/busybox /bin/egrep /bin/mkdir /bin/pidof
/bin/systemd-notify
/bin/bzcat /bin/false /bin/mknod /bin/ping /bin/systemd-
tmpfiles
/bin/bzcmp /bin/fgconsole /bin/mktemp /bin/ping6
/bin/systemd-tty-ask-password-agent
/bin/bzdiff /bin/fgrep /bin/more /bin/plymouth /bin/tailf
......................................
/bin/echo /bin/ls /bin/ntfswipe /bin/systemd-hwdb /bin/znew
student@mca25:~$

2. Display the type of file of /bin/cat, /etc/passwd and usr/bin/passwd.

student@mca25:~$ file /bin/cat /etc/passwd /usr/bin/passwd


/bin/cat: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically
linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32,
BuildID[sha1]=2267d831560007f67fa4388d830192fd89861061,
stripped/etc/passwd: ASCII text
/usr/bin/passwd: setuid ELF 64-bit LSB shared object, x86-64, version 1 (SYSV),
dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32,
BuildID[sha1]=40a9016718f4247f09acc62e1bbf056372bf31f5, stripped
student@mca25:~$

3. Create a directory mywork and enter it.

student@mca25:~$ mkdir mywork


student@mca25:~$ cd mywork/
student@mca25:~/mywork$

4. Create two files file1.txt and file2.txt in mywork.

student@mca25:~/mywork$ touch file1.txt file2.txt


student@mca25:~/mywork$ ls
file1.txt file2.txt
student@mca25:~/mywork$
5. Change the date on file1.txt to yesterdays date.

student@mca25:~/mywork$ touch -t 06071320 file1.txt


student@mca25:~/mywork$ ls -ltr
total 0
-rw-rw-r-- 1 student student 0 Jul 7 13:20 file1.txt
-rw-rw-r-- 1 student student 0 Jul 8 13:50 file2.txt
student@mca25:~/mywork$

6. Copy file1.txt to copy.file1.txt

student@mca25:~/mywork$ cp file1.txt copy.file1.txt


student@mca25:~/mywork$

7. Rename copy.file1.txt to myfile

student@mca25:~/mywork$ mv copy.file1.txt myfile


student@mca25:~/mywork$

8. Create a directory called testbackup in the home folder and copy a few files from
/etc to it.

student@mca25:~/mywork$ mkdir ~/testbackup


student@mca25:~/mywork$ cp /etc/a* ~/testbackup/
student@mca25:~/mywork$

9. Use one command to remove testbackup and all files in it.

student@mca25:~/mywork$ rm -r ~/testbackup/
student@mca25:~/mywork$

10. Create a directory etcbackup and copy all the files *.conf from /etc.

student@mca25:~/mywork$ cp /etc/*.conf ~/mywork/etcbackup/


student@mca25:~/mywork$

11. Rename all files having *.conf with *.backup.

student@mca25:~/mywork/etcbackup$ rename 's/.conf$/\.backup/' *.conf


student@mca25:~/mywork/etcbackup$ ls -ltr
total 188
-rw-r--r-- 1 student student 1018 Sep 5 19:29 usb_modeswitch.backup
-rw-r--r-- 1 student student 338 Sep 5 19:29 updatedb.backup
..........
-rw-r--r-- 1 student student 3028 Sep 5 19:29 adduser.backup
student@mca25:~/mywork/etcbackup$

Potrebbero piacerti anche