UNIX QUESTIONS 1. How do I list all the files that are in the current directory?
ID: 3856926 • Letter: U
Question
UNIX QUESTIONS
1. How do I list all the files that are in the current directory?
2. What is the command to search all files in your current directory for the word "awesome"?
3. What is the command to use if you want to rename a file called badfile.txt to goodfile.txt
4. How would I change the current directory to a directory called HW_7 that is inside of a directory called Homework, which is inside of your home directory?
5. What command would be use to change the permissions on a file called my_work.txt to allow the file to be executable.
Explanation / Answer
1) How do I list all the files that are in the current directory?
Answer : You can use the ls command to list the files in any directory to which you have access. For a simple directory listing, at the Unix prompt, enter: ls
This command will list the names of all the files and directories in the current working directory.
Examples :
ls hello : Lists files whose complete name is hello; if hello is a directory, displays the contents of the hello directory.
ls hel* : Lists all files in the directory that begin with the characters hel (e.g., files named hel, hello, and hello.officer).
ls hell? : Lists files that begin with hell followed by one character, such as helli, hello, and hell1.
The * represents any number of unknown characters, while ? represents only one unknown character. You can use * and ? anywhere in the filename fragment.
2) . What is the command to search all files in your current directory for the word "awesome"?
Answer : command to search all files in your current directory for the word "awesome" : grep awesome *
3). What is the command to use if you want to rename a file called badfile.txt to goodfile.txt
Answer : The mv is a Unix command that renames one or more files or directories. The original filename or directory name is no longer accessible. Write permission is required on all directories and files being modified. Use the mv command to:
Syntax :
mv old-file-name new-file-name
mv file1 file2
mv source target
mv [options] source target
Example :
mv badfile.txt goodfile.txt
ls -l goodfile.txt
File is renamed
4). How would I change the current directory to a directory called HW_7 that is inside of a directory called Homework, which is inside of your home directory?
Answer: cd /HW_7/homework
5) What command would be use to change the permissions on a file called my_work.txt to allow the file to be executable.
Answer : Making a File Executable
Issue the following command to change the file permissions so that any user can execute the file my_work.txt:
Example:
chmod +x ~/my_work.txt
Permissions:
0 --- indicates no permissions
1 --x indicates execute permissions
2 -w- indicates write permissions
3 -wx indicates write and execute permissions
4 r-- indicates read permissions
5 r-x indicates read and execute permissions
6 rw- indicates read and write permissions
7 rwx indicates read, write, and execute permissions
Thanks...
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.