Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have a few questions that I would like answered. If any of you can help me please do.
1)Using vi, in the command mode, what command will change all the occurrences of the word "bad" in lines 3-9 to "good"?2)Which ONE command will list files in my current directory, SORTED so the most recently accessed file is last in the list?
3)I don't want everyone else seeing the contents of my home directory, but I want them to still be able to change their current directory to my home directory. I need the commands to do this.
4) Using vi to modify my file called h1.c I have already modified the file. I am in the insert mode and I want to save the file and exit. I need the commands that need to be done in the order in which they should occur.
5)I also need to write a shell script to do the following.
-List all the files in my current directory having 2 or more characters in their filenames.
-Recursively copy a directory d1 to another directory d2, assuming both d1 and d2 are under root directory.
-Prints the lines in file f1 that have both the words hot or cold in them, assuming f1 is in my current directory
-Edit the file test.txt using the vi editor, starting from where the word "test" first occurs, assuming test.txt in my current directory
-Redefine the command ls to be able to list hidden files

Wow, and your homework is due when?
As far as the vi stuff:
#1 while in vi, :3,9s/bad/good/g#4 while in vi, :wq (if that does not work try :wq!)
The rest I currently do not have time for, good luck.

Regarding #4, you must first get out of insert mode with the escape key:
Esc :wq
or Esc ZZ#2: ls -ltur
-t gives time sort instead of filename
-u says use access time (for sort and
display) instead of modify time.
-r reverses the sort#3: cd;chmod 711 .
Above commands puts you in your home dir, then sets permissions on current dir. You don't have to be in a directory to change permissions on it, but you must be the owner or root. Instead of above, you could do, from any directory:
chmod 711
First digit (7) gives full permissions (rwx) to the owner. 2nd & 3rd digits give execute permission to group users and others, which will allow cd but not ls.5: I will provide individual answers, and you can construct a single script if needed. But the vi is for interactive and not for a script.
5a:
ls -ld ??*Above will list files AND dirs with 2+ characters in filename/dirname. Include the -d to list only the dirname and not dir contents. -l is optional here.
To list regular files only, and exclude dirs and other special files such as links and pipes, I do:
ls -ld ??* | grep "^-"
in which case -l is required.5b:
cp -R /d1 /d2The cp command will yield different results depending on if /d2 already exists or not. The problem does not make it clear if /d2 already exists. To handle either case, do:
if test -d /d2 ; then
cp -R /d1/* /d2
else
cp -R /d1 /d2
fi5c:
grep -e hot -e cold f1Above solution prints lines having EITHER hot OR cold on a line. To print lines having both: grep hot f1 | grep cold
I think XPG4 version is required for multiple -e search strings.5d:
vi -c /test test.txtAt startup, vi will execute the command specified by -c (forward search on test).
5e:
alias lsh='ls -ld .*'I use alias here to define a new command, which is not supported by some bourne shells. The problem seems to ask for a command that lists ONLY hidden files, which is why I am targeting .*, and as such I do not need the -a option. The pseudo directories of . and .. also qualify here. To weed them out, do:
alias lsh='ls -ld .*|grep "^-"'
James

![]() |
load a file into memory
|
Advise me PLEASE
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |