In: Computer Science
Linux Fundamentals part 3 Below are questions related to the command line use of Linux. You can use the videos, man pages, and notes to answer these questions. Remember that Linux is CASE SENSITIVE. Rm and rm are NOT the same command. I will count off totally for a question if you do not take this into account. For each command give me the ENTIRE COMMAND SEQUENCE. If I ask you 'What command would I use to move the file one.txt to the parent directory and rename it to two.txt?", the answer is NOT 'mv'. That is only part of the command. I want the entire command sequence.
10. Find all files under the current directory with an accessed time was more than 2 days ago.
11. I have a file called 'BackupLogs.tar.bz2' in my home
directory (because you made it from Questions 4 and 8, right?
Right!). I want to uncompress and unarchive the files in it. What
single command would I use?
12. I have a file called BackupLogs.tar.bz2 and I want to
uncompress and ONLY uncompress the file (NOT uncompress and
unarchive). What command would I use?
13. I want to search for all files in the directory ~/Documents
which contain the keyword "add", case sensitive, and as the whole
word only. Words like addendum, addition, etc, should not be found
in the results; just 'add'. Additionally, I only want to see the
name(s) of the file(s) that have matches as a result of running the
command. This means your result should show not the keyword hit AND
surrounding text, but rather suppress that output and instead
display just the file name. What command would I use? This may
sound complicated, but break down each step and use the man
page.
14. I have a large file named walloftext.txt and I want to view
only the first 5 lines of the file. What command would I
use?
15. Same as file as Question 14, but I want to view only the
last 7 lines.
Q 10.
find -iname "*" -mtime +2 -print [For all files]
find -iname "*.txt" -mtime +2 -print [for txt file] you can add any extension
-mtime +2 looking for a file modified 2 days ago.
-mtime -2 less than 2 days.
-mtime 2 exactly 2 days.
Q.11
tar -cvzf BackupLogs.tar.bz2 BackupLogs [ compress and archive in single command]
tar -xvzf BackupLogs.tar.bz2 [if you zip with sudo then sudo use for uncompress and unarchivealso)
-x: Extract.
-v: Verbose
-j: Bzip2
-f: File
Q12
ONLY uncompress the file
bunzip2 BackupLogs.tar.bz2 [output will be BackupLogs.tar]
Q13
grep -w "add" *
-w for whole words only and * for find from all files from Documents
Q14
head -5 walloftext.txt [ -5 for first 5 lines]
also you can see last 5 lines use only tail insted of head
Q15
tail -7 walloftext.txt [you will get last 7 lines]
---------------------------------------------
hope this will help you .