Linux Command Questions 1. What is the command that you issue if you are in your
ID: 3826444 • Letter: L
Question
Linux Command Questions
1. What is the command that you issue if you are in your home directory and want to copy all files and directories under “/directory1” to “directory / directory2”?
2. How to change the name of the file “oldhosts” to “newhosts”? How to change the permissions of the file “oldhosts” such that other users can read but not write to it? And then what is the command to Find Files with 777 Permissions?
3. Let’s say that you have an entire folder full of music files in a bunch of different formats. You want to find all the “*.mp3” files from the artist “JayZ”, but you don’t want any of the remixed tracks. What will you do for it?
4. Count the number of files in your home directory which are not readable. (Hint: using script)
5. Display the longest and shortest usernames on the system (You should have at least three account on your Linux. Usernames are in the first field in /etc/passwd). (Hint: using script)
Explanation / Answer
ANS 1.
ANS 3.
In this example, we are using find to print all of the files with a *.mp3 extension, piping it to grep –i to filter out and prints all files with the name “JayZ” and then another pipe to grep –vi which filters out and does not print all filenames with the string (in any case) “remix”.
ANS 5:
#!/bin/bash
MAX_LEN=0
MIN_LEN=100
for USER_NAME in $(cut -f1 -d: /etc/passwd)
do
if [[ ${#USER_NAME} -gt MAX_LEN ]]
then
MAX_LEN=${#USER_NAME}
MAX_LEN_USERNAME=$USER_NAME
elif [[ ${#USER_NAME} -lt MIN_LEN ]]
then
MIN_LEN=${#USER_NAME}
MIN_LEN_USERNAME=$USER_NAME
fi
done
echo “The longest user name is $MAX_LEN_USERNAME”
echo “The shortest user name is $MIN_LEN_USERNAME”
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.