This is for my linux class Write a script called activity427
This is for my linux class.
Write a script called activity4.2-7 that iterates through the contents of your working directory and display the regular file names. Include a rst line that calls the bash shell as the interpreter Add a comment to state the purpose of the script and other comments to make the script easier to read
Solution
#!/bin/bash
#This script iterates through the contents of working directory and display the regular file names
#now go through each file and echo only file not directory using grep ^d on ls -ld on list variable
for list in `ls` ;
do ls -ld $list | grep ^d > /dev/null || echo $list ;
done ;
-------------------------
save above script as activity4.2-7
------------------------------------
output
present working directory has following files
-rwxr-xr-x 1 51613 51613 193 Feb 6 15:57 Newfile.sh
-rw-r--r-- 1 51613 51613 0 Feb 6 15:50 main.o -rw-r--r-- 1 51613 51613 141 Feb 6 15:50 main.sh
drwxr-xr-x 2 51613 51613 6 Feb 6 15:50 test drwxr-xr-x 2 51613 51613 6 Feb 6 15:58 test1
run the above script as follow and it produce output after executing script
./activity4.2-7
activity4.2-7
main.o
main.sh
test1 and test directory are not listed.
