Check out the Pastebin Gadgets Shop. We have thousands of fun, geeky & affordable gadgets on sale :-)Want more features on Pastebin? Sign Up, it's FREE!


By: a guest on May 15th, 2011  |  syntax: None  |  size: 1.69 KB  |  views: 3,289  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print  |  QR code  |  clone
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.                                                   UNIX Assignment No. 1
  3. Question 1:
  4. Write a command to list all the files inside a folder i.e. if there is a folder inside a folder then it should list all files inside the sub-folder which is inside the folder to be listed.
  6. Ans:- ls -R
  7. Question 2:
  8. Search all the files which contains a particular string, say “include” within a folder.
  9. Ans – ls -l | grep include
  11. Question 3:
  12. Rename all the files within a folder with suffix “Unix_” i.e. suppose a folder has two files a.txt and b.pdf than they both should be renamed from a single command to Unix_a.txt and Unix_b.pdf
  13. for f in * ; do mv "$f" Unix_"$f" ; done
  15. Question 4:
  16. Rename all files within a folder with the first word of their content(remember all the files should be text files. For example if a.txt contains “Unix is an OS” in its first line then a.txt should be renamed to Unix.txt
  17. ans:-
  18. for f in *.txt; do d="$(head -1 "$f") ;x=”$(cut -d " " -f1 $f)” ; mv $f $x; done
  20. Question 5:
  21. Suppose you have a C project in a folder called “project”, it contains .c and .h files, it also contains some other .txt files and .pdf files. Write a Linux command that will count the number of lines of your text files. That means total line count of every file. (remember you have to count the lines in .txt files only)
  22. ans:-
  23.  wc -l *.txt
  26. Question 6 :
  27. Rename all files which contain the sub-string 'foo', replacing it with 'bar' within a given folder.
  28. Ans:-
  29. for i in ./*foo*;do mv -- "$i" "${i//foo/bar}";done
  31. Question 7:
  32. Show the most commonly used commands from “history”. [hint: remember the history command, use cut, and sort it]
  33. ans:-
  34. history|sort|cut –d-10 -n
clone this paste RAW Paste Data