Renaming a '.' file in Ubuntu [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I downloaded a file using rsync and accidentaly provided it the destination as '.' (I thought it is the directory to download into). So it downloaded the multi-gig file but named it '.'.
drwxr-sr-x 2 root apache 4096 May 7 00:42 .
drwxr-sr-x 7 me apache 4096 May 7 00:25 ..
-rw-r--r-- 1 1006 1006 2008805206 Apr 5 04:49 .
-rw------- 1 root apache 1675 May 7 00:25 somefile
-rw------- 1 root apache 392 May 7 00:26 anotherfile.txt
How do I rename the 2GB+ '.' file to something meaningful. Nothing I do seems to work (i've tried mv, rename, etc.) but they all say
Device or resource busy

You can use this mv:
mv ./.[[:blank:]]* myfile
Or else try this find:
find . -type f -maxdepth 1 -name '. *' -exec mv '{}' myfile \;

Yes its a superuser question. But I found a solution elsewhere, so thanks everyone for trying. We could do this using:
find . -type f | (let i=0; while read f; do mv "$f" "$f"-$i ; let i=$i+1; done)
Not the most elegant way and probably very insecure too (as there is no undo).

Type this from the directory where it is located.
mv ./. newfile

Related

How to handle files with leading dashes [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
I am searching for files and directories using find, the files have leading dashes in the filenames:
ls -al
total 0
-rw-r--r-- 1 razhal staff 0 May 22 23:58 -x
drwxr-xr-x 3 razhal staff 96 May 22 23:58 .
drwxr-xr-x 12 razhal staff 384 May 22 17:06 ..
find * -maxdepth 1 -type file
The above gives the following error message:
find: illegal option -- m
I tried to terminate the options using --, but still having the same problem:
find * -maxdepth 1 -type file --
The strange thing is that if the folder contains a file without a leading dash I am getting no error message:
ls -al
total 0
-rw-r--r-- 1 razhal staff 0 May 22 23:58 -x
drwxr-xr-x 3 razhal staff 96 May 22 23:58 .
drwxr-xr-x 12 razhal staff 384 May 22 17:06 ..
-rw-r--r-- 1 razhal staff 0 May 23 00:03 x
find * -maxdepth 1 -type file
The above returns the x and no error message.
My question is how can I find and list both files/directories with and without leading dashes using find?
Notice that I really want to use find and not some other command such as xargs or similar.
Use . instead of *:
find . -maxdepth 1 -type file
. refers to the current folder you are in. You can also use .. instead of . to search from the parent directory.
Another option would be to put ./ in front of * like this:
find ./* -maxdepth 1 -type file
This way it won't interpret the files whose names start with a dash as options.

Susu Linux delete directory older than 1 day [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
Please help
I want to delete the directory and corresponding sub directories from a path and i tried the below command and for some reason it is not deleting .
Any help is appreciated .
/hana/export/PHO> ls -lrt
total 0
-rwxr-x--- 1 phoadm sapsys 678 Sep 4 10:59 export_schema.sh
drwxr-x--- 50 phoadm sapsys 4096 Sep 5 00:23 2018-09-05
drwxr-x--- 50 phoadm sapsys 4096 Sep 6 00:23 2018-09-06
-rwxr-x--- 1 phoadm sapsys 248 Sep 6 00:23 export_schema.out
phoadm#SS4100:/hana/export/PHO> find /hana/export/PHO/* -type d -ctime +1 -exec rm -rf {} \;
phoadm#SS4100:/hana/export/PHO> find /hana/export/PHO/* -type d -mtime +1 -exec rm -rf {} \;
phoadm#SS4100:/hana/export/PHO>
It should delete 2018-09-05 directory but for some reason the above command not working .
Thanks
I think it should be
find /hana/export/PHO -type d -ctime +1 -exec rm -rf {} \;
(without "*"), otherwise you are looking inside the directories not in PHO as you want, because "*" will be expanded by the shell.
or this:
find /hana/export/PHO/ -type d -mtime +1 -delete

find -amin doesn't work if -name is excluded [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I am running GNU Linux 6.2 on x86_64 hardware. I'm in a directory with 1237 files. I want to list the files created in the last 36 hours and since I cannot get -atime to work, I use "-amin 2160":
$ find . -amin -2160 -name 'Ar*' -exec ls -l {} \;
-rw-r--r-- 1 oracle dba 2318 Aug 30 04:04 ./Archivelog_backup_08302015040300.log
-rw-r--r-- 1 oracle dba 2317 Aug 30 10:03 ./Archivelog_backup_08302015100321.log
-rw-r--r-- 1 oracle dba 1920 Aug 30 16:21 ./Archivelog_backup_08302015160300.log
-rw-r--r-- 1 oracle dba 2318 Aug 30 22:04 ./Archivelog_backup_08302015220300.log
-rw-r--r-- 1 oracle dba 2318 Aug 31 04:03 ./Archivelog_backup_08312015040300.log
-rw-r--r-- 1 oracle dba 2318 Aug 31 10:04 ./Archivelog_backup_08312015100320.log
But since I don't care what the name is and I want to see ALL files touched in the last 2160 minutes, I type this command,
find . -amin -2160 -exec ls -l {} \;
but it lists all 1237 files in the directory PLUS THE 6 that meet the criterion. Why?
Humbly,
Because one of the matches is the directory entry.
The real lesson here is to not use ls in scripts. find has excellent, unambiguous replacements like the -printf predicate. See also http://mywiki.wooledge.org/ParsingLs
You probably also want to add -type f to avoid listing directories.
find . -type f -amin -2160 -printf '%s %f\n'
What you put in the format string obviously depends on which information exactly you actually want to extract for each matched file.
The first name output by
find .
is
.
which, when sent to ls will list all the files in the current directory. In your first example, . was excluded by -name "Ar*" You could get the same effect by telling find to only emit regular-files (not directories) with
find . -type f …

What is the linux command to give execution permission of all files in current folder [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
Remember I need the command to change permissions of all files in current folder?
It depends on what you mean by "current" folder; if you mean the current folder (and all subfolders) then you could use find and chmod like so -
find . -type 'f' -exec chmod +x {} \;
If you mean the current folder (and no sub-folders) then you would use it like so -
find . -maxdepth 1 -type 'f' -exec chmod +x {} \;
OR you could use find (possibly with maxdepth) and xargs likes so
find . -print0 | xargs -0 chmod +x
Note that these commands will correctly handle files with spaces in the name and most other edge cases.
Use chmod with a glob:
chmod +x *
(Technically that will give permission to list directories, too, but that shouldn't be a problem.)

how to remove a file named "?" in linux? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
I created a file named "?", is anybody know how to delete it?
It seems that ? is a special character in linux, I use Redhat as my OS.
I have already tried
rm ?
rm "?"
rm \?
They all failed and I got the error indicated that the file doesn't exist.
find the inode of the file:
ls -li
then delete the file using inode:
find . -inum <inode-number> -exec rm -i {} \;
BTW, rm ? works for me fine. here is my bash version:
# bash --version
GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)
rm \? and rm "?" are both perfectly good ways to delete a file named ?. If they didn't work, and you still seem to have a file name ?, then it is most likely that the ? being shown is not really a ?, but rather the result of substituting an unprintable character with a ?. To see what the file is really called (with GNU ls) try:
ls --quoting-style=escape
Use this rm command to remove a file named ?:
rm ./\?
OR from another directory:
rm /path/to/\?
You can delete the file by its inode number. see the output bellow:
alplab:~/cad# ls -il
63051 -rw-r--r-- 1 root root 0 Nov 12 11:48 ?
alplab:~/cad# find . -inum 63051 -exec rm -i {} \;
I used the "find" command to delete the file with the inode number 63051 (the inode belonging to my "?" file).

Resources