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 ?
 


wizardfromoz

Administrator
Staff member
Gold Supporter
Joined
Apr 30, 2017
Messages
7,298
Reaction score
6,195
Credits
24,880
Welcome to linux.org.

Moving this to Command Line, where scripting is handled.

Good luck.

Chris Turner
wizardfromoz
 

dos2unix

Well-Known Member
Joined
May 3, 2019
Messages
1,443
Reaction score
1,050
Credits
8,907
For item 3. check out ls flags. Maybe ls -lrt

For item 4. check out chmod.

man chmod
man ls
 
OP
A

Athin

New Member
Joined
Jul 8, 2022
Messages
3
Reaction score
0
Credits
25
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
 

shubhamsharma9418

New Member
Joined
Jul 13, 2022
Messages
5
Reaction score
2
Credits
52
@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
 
OP
A

Athin

New Member
Joined
Jul 8, 2022
Messages
3
Reaction score
0
Credits
25
@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
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Linux.org Hosting Donations
Consider making a donation

Members online


Top