how to remove a file named "?" in linux? [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 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).

Related

Linux shell select files in directory and subdirectiry [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
For selecting all php files in a folder , we use :
vim *.php
How to use this command for selecting *.php files in this directory and his subdirectories ?
With shell option `globstar`` in bash you can use
vim **/*.php
To enable the shell option use e.g.
shopt -s globstar
You can use find combined with xargs:
find . -type f -name '*.php' -print0 | xargs -0 vi
The find will locate all regular files matching *.php, in and below the current directory, and send all the names in a stream to xargs separated by NUL characters.
The xargs program (with a -0 matching the -print0) will then separate them into individual file names and pass as many as possible to a single vi invocation. If it can't fit them all in one invocation (unlikely, unless the number of files is truly massive), it will make multiple invocations as needed.
You could use brace expansions:
vim {,*/}*.php
How does it work
{,*/} expands to <empty> dir1/ dir2/ ...
the final command line is then: ls *.php dir1/*.php dir2/*.php ...
This only matches immediate subdirectories, so subdirectories of a subdirectory won't be included. As mentioned in the other answeres, find or globstar is better suited for that.

How to search for a string in entire linux system? [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 looking to search for a string for example "/uniquexx" in the entire hard drive and find the files where it is referenced? How could I do that? I tried grep and find / but no luck
grep -r blablastring /
-r means recursive searching from all subdirectories.
If you want to search only text files, try ack. It's like grep, but defaults to skipping file types it recognizes as binary. It also highlights matches by default, when searching recursively in a directory.
Some answer point with use of grep.
What this actually does is make a list of every file on the system, and then for each file, execute grep with the given arguments and the name of each file
use
find / -xdev '(' -type f -a -name '*.txt' -a -size -2M -a -mtime -5 ')' -print0 | xargs -0 grep -H "800x600"
read more: How to search text throughout entire file system?
You can try:
grep -r -H "your string" /home/yourdir
-H means you will shown the filename contains your string.
Anyway if you want to search within the WHOLE linux directory, you need sudo privileges.

Move all files whose names contain a capital letter from source directory to target directory? [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
How to write this linux command?
Move all files whose names contain a capital letter from source directory to target directory?
If I read your question correctly, use this:
mv src/*[A-Z]* target/
The obvious but wrong solution is
mv src/*[A-Z]* dest
However, the order of letters is locale dependent. [A-Z] therefore can contain lower case letters:
$> touch abc aBc
$> export LC_ALL=C
$> ls *[A-Z]*
abc
$> LC_ALL=en_US
$> ls *[A-Z]*
aBc abc
so make sure to set LC_ALL properly.
export LC_ALL=C
mv src/*[A-Z]* dest
BTW: *[A-Z]* is evaluated by the shell, not mv. Therefore the following does not work:
LC_ALL=C mv rc/*[A-Z]* dest ## does not work
This version ensure that only "Files" in root source folder are moved to target directory:
find /source/*[A-Z]* -maxdepth 1 -type f -exec mv {} /target \;

Linux/Unix Command Needed for finding files on a particular date [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
I need help finding files in a directory which contain a word/string and on a particular date.
Currently I am using this command:
find . -exec grep -l .string. {} \;
This command returns all the files containing that string in that directory. I would like to get those files on from a particular date, for example 12/24/2013.
You can use:
find . -type f -exec grep 'string' {} \; -exec ls -l {} \; | grep 'Dec 24'
Which will search any files which contain the string string, and then execute ls -l on only those files, and finally, grep out any that match Dec 24.
This works because find will apply it's arguments in order, so only those that match previous results will be passed on.
Maybe this could help you with grep:
find /path/to/find -type d -atime -7
The last parameter is days here 7 days before you can modify to particular dat ,atime is the file access time ,'d' is directory search for directory for find a file replace 'd' with 'f' give the path where to find and then finally make pipeline this with grep to string to search

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.)

Resources