Bash script

Athin

New Member
Joined
Jul 8, 2022
Messages
3
Reaction score
0
Credits
25
Hello Folks,
I am a newbie to the Linux.
I have been trying to write a bash script for the task below,

1, create a directory under your home folder which will create 10 temp files in the series
(files1, files2, files3 .. )
2, add Extension ".new" to all the files in a directory.
3, print the last updated file
4, change the last updated file permission to 600

Code I wrote
#!bin/bash

for i in {1..10}
do
mktemp --suffix=.new file$i.XXX
Done

Does anyone know what more codes to be added inorder include point 3 and 4 ?
 


Welcome to linux.org.

Moving this to Command Line, where scripting is handled.

Good luck.

Chris Turner
wizardfromoz
 
For item 3. check out ls flags. Maybe ls -lrt

For item 4. check out chmod.

man chmod
man ls
 
For item 3. check out ls flags. Maybe ls -lrt

For item 4. check out chmod.

man chmod
man ls
Thank you, but I am looking for guidance in how to add those commands into the script
 
@Athin here is your script code :

#!bin/sh
for i in {1..10}
do
mktemp --suffix=.new file$i.XXX
done
getLatestFile=$(ls -Art | tail -n 1)
echo "Last Modified File :" $getLatestFile
chmod 600 $getLatestFile


- Code will create 10 files
- Add Extension ".new" to all the files in a directory.
- Prints the last updated file
- Change the last updated file permission to 600
 
@Athin here is your script code :

#!bin/sh
for i in {1..10}
do
mktemp --suffix=.new file$i.XXX
done
getLatestFile=$(ls -Art | tail -n 1)
echo "Last Modified File :" $getLatestFile
chmod 600 $getLatestFile


- Code will create 10 files
- Add Extension ".new" to all the files in a directory.
- Prints the last updated file
- Change the last updated file permission to 600
Thanks mate, it works
 

Staff online


Latest posts

Top