Bash: How to list only files with read permissions? [duplicate] - linux

This question already has answers here:
Find all writable files in the current directory
(11 answers)
Closed 7 years ago.
How can I list all the files with read permissions on current directory ?

find -maxdepth 1 -type f -perm xxx
Where xxx indicate the file permission on your targer file, according to this question.

Related

How to write script displaying all subdirectories in the location [duplicate]

This question already has answers here:
List sub-directories with ls [closed]
(3 answers)
Closed 3 years ago.
I need help. How to write script displaying all subdirectories in the location. I've got something like that:
ls -al | grep ^d
but it only works in the home directory
find(1) may be a better choice here:
find . -type d
which would list all directories from the current directory and all subdirectories.

shell command to extract the part of filename having characters? [duplicate]

This question already has answers here:
Extract filename and extension in Bash
(38 answers)
In Bash, how to strip out all numbers in the file names in a directory while leaving the file extension intact
(1 answer)
Closed 5 years ago.
I have a file named(multi_extension123.txt). Before copying this file into the directory I need to remove files like
[multi_extension1234.txt
multi_extension1234.txt
multi_extension12345.txt] if present in the directory and then copy the earlier one to this directory. Can anyone give the solution with shellscript.
note: i need to remove only numerical numbers and extension alone.
I have tried this
$ filename= $file1
$ echo "${filename%[0-9].*}"
find . -type f maxdepth 0 mindepth 0 -name "'$filename'[0-9]*.txt" -exec rm -f {} \;

Unix backup script [duplicate]

This question already has answers here:
How do I set a variable to the output of a command in Bash?
(15 answers)
Closed 6 years ago.
I am trying to learn scripting in Ubuntu.
I need to backup files created by a specific user in a folder where other users store there files. It needs to be compressed into a tar file with the file tree intact.
Edit: How do I find those files created by a user and then compressing them into a tar file with all the direcories and subdirectories
FILENAME=user_archive.tar
DESDIR=/home/user
FILES=find /shared -type d -user user * tar -rvf $DESDIR/$FILENAME
tar -jcvf $DESDIR/$FILENAME
As suggested by #Cyrus and using shellcheck, you keep the following error
To assign the output of a command, use var=$(cmd)
Then you get some errors to correct and here a working script
FILENAME=user_archive.tar
DESDIR=/home/user
FILES=$(find /shared -type d -user user)
tar -jcvf $DESDIR/$FILENAME $FILES

Bash - find files older than X minutes and move them [duplicate]

This question already has answers here:
find files older than X days in bash and delete
(3 answers)
Closed 7 years ago.
I need to create a bash script and put in CRON - on linux.
I need to loop through or just find all files in directory DIR_A and if files are older than, for example, 10 minutes, move them to directory DIR_B.
Any ideas? Thanks!
If anyone else needs it:
find DIR_A -maxdepth 1 -type f -mmin +10 -exec mv "{}" DIR_B/ \

How to find both files and folders that are used in some process? [duplicate]

This question already has answers here:
Delete files older than 10 days using shell script in Unix [duplicate]
(3 answers)
Closed 7 years ago.
I want to delete files and folders older than 15 days.
But Before deletion I want to check that those file and folders shouldn't use anywhere. How can i do that ?
is ps -ef works for this ?
Using the find command:
find /path/to/folder -type f -mtime +15 -delete

Resources