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
8,627
Reaction score
7,584
Credits
35,284
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,775
Reaction score
1,380
Credits
11,909
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
 
MALIBAL Linux Laptops

Linux Laptops Custom Built for You
MALIBAL is an innovative computer manufacturer that produces high-performance, custom laptops for Linux.

For more info, visit: https://www.malibal.com

Members online


Top