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
My website was recently hacked and had a number of malicious files on the server. They all had the -i and -a extentions added to them
I found this out using
lsattr command and then used
chattr -ai <Filenames> to remove the immutable and append only attributes
Then rm -f <Filenames> to remove
All good
However there is one file
$$222.php which cannot be removed
When I do anything with the filename $$222.php it returns
No such filename or directory whilst trying to stat 761022.php
How can I delete this file?
This is easily duplicated.
mkdir SO
cd ./SO
echo > '$$$222.php'
ls
$$$222.php
OK we have one of these, and if you try to rm...
rm $$$222.php
rm: cannot remove ‘351522.php’: No such file or directory
We can confirm that the $$ is transformed by the shell to the process ID number.
ps
PID TTY TIME CMD
3515 pts/8 00:00:00 bash
7671 pts/8 00:00:00 ps
Turns out 3515 is just bash's process id number or PID, which occurred because the shell transforms $$ to the PID.
echo $$
3515
And it becomes 351522 not 3515222 because $2 refers to the 2nd argument to the command bash which was blank.
You can use rm -i with a wildcard to remove it, and the -i will ask you if you are sure you want to remove each matching file:
rm -i *php
rm -i *222.php
Or you can use single quotes, rm '$$$222.php'
Double quotes rm "$222.php" will still be transformed by the shell and will be transformed where it will not match.
Related
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 want to rename all files in selected directory using rename command or move command from :
_02_mp3_cbr_320.m4a?anghakamitoken=sc245ae5a454547.5
_02_mp3_fsgsfsdfsfdfdsfcbr_320.m4a?anghakamitoken=sc245.ae5a
to
1.m4a
2.m4a
If those files always have a sheme like this:
_02_mp3_ * _320.m4a?anghakamitoken= *
You can do it like that:
#!/bin/bash
COUNT=0
for f in ./"_02_mp3_"*"_320.m4a?anghakamitoken="*; do
mv $f "$((++COUNT)).m4a"
done
This will result in
1.m4a
2.m4a
Assuming the initial files are in the same directory as the bash script.
Try this with GNU Parallel. it basically uses GNU Parallel's job number ({#}) as the number for renaming:
parallel --dry-run -k mv {} {#}.m4a ::: *m4a*
Sample Output
mv _02_mp3_cbr_320.m4a\?anghakamitoken\=sc245ae5a454547.5 1.m4a
mv _02_mp3_fsgsfsdfsfdfdsfcbr_320.m4a\?anghakamitoken\=sc245.ae5a 2.m4a
If the commands look correct, remove the --dry-run part and run it again. The -k keeps the output in order. The {} refers to the current file.
Make a backup before using any commands you are unfamiliar with...
To rename any file in Linux using mv (move) command:
mv (cfr. "man mv")
In this case, you need to enter the following lines on the command line:
$mv _02_mp3_cbr_320.m4a?anghakamitoken=sc245ae5a454547.5 1.m4a
$mv _02_mp3_fsgsfsdfsfdfdsfcbr_320.m4a?anghakamitoken=sc245.ae5a 1.m4a
It is important that you refer to the manual when you know the command you must use, to understand how to use it.
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
As far as you know, - has different usages for in combination with different commands in Linux. For example in combination with cd command, it means "Change directory to the previous location" and in combination mv or cat command it means stdin or stdout.
Unfortunately I wrongly used this character with mv command. I wanted to move my file to the previous location which I have been before the change directory but I moved it to stdin instead.
Is there any way to recover my file?
I run this command:
# mv myfile -
I moved it to stdin instead.
No, you moved to a file literally named by a dash (you'll use /dev/stdin or /proc/self/fd/0 to refer to the stdin, i.e. the file descriptor 0).
You want to
mv -i ./- myfile
this is usual practice (to prefix by ./ a strange path). The -i interactively asks for confirmation.
Sometimes it is not even easy to type a path for a weird file (e.g. for a file name containing a single newline character). You could use globbing (read about shell expansion), e.g. mv -i ./? file.
See mv(1) and path_resolution(7) and glob(7) and proc(5)
The good habit is to avoid strange characters in file paths.
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 6 years ago.
Improve this question
I've been reading how running rm -rf to delete files and directories isn't a good idea because of how dangerous it can be, but can't seem to find a consensus on how to safely delete files and directories through the terminal. Is there another command built into Linux that does this safely?
Consider using the -i or -I options, ie.
$ rm -i foo
$ rm -I foo
Those tell rm to be interactive, prompting you to confirm deletion of files.
From the rm(1) manpage:
-i prompt before every removal
-I prompt once before removing more than three files, or when
removing recursively; less intrusive than -i, while still giving
protection against most mistakes
For example:
$ mkdir -p ~/foo/{bar,baz} # make some dirs
$ touch ~/foo/{bar,baz}/{1,2,3} # add some empty files
$ rm -ir ~/ foo # note the "accidental" space between `~/` and `foo`
rm: descend into directory '/home/uz0r/'? y # haven't noticed yet...
rm: remove regular file '/home/uz0r/.bashrc'? # ...wait, what?
"Hold on... I told you to delete $HOME/foo, not $HOME! Or did I...?"
So you made a typo, but -i saved you from an accident. Now you can tell rm to stop, then try again after correcting the typo.
Be careful using -f! It counteracts the above safety nets by telling rm to "never prompt":
-f, --force
ignore nonexistent files and arguments, never prompt
Create yourself a trash bin for your deleted objects.
mkdir ~/trash
mv xyz ~/trash
You can recover, just be aware that some privileges may change on the files.
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 6 years ago.
Improve this question
I'm trying to wrap my head around the 'ls -d' command.
I run the command 'ls -d' in any given directory and all I get is a '.'
I run the command 'ls -d */ and I get only the directories
I run the command -ls -d * and I get all files, including those that aren't directories.
The man page just states this:
list directories themselves, not their contents
Can someone please help explain how this switch is supposed to work?
The things to understand are:
ls lists the current directory, otherwise known as ., by default.
ls -d makes ls show the directory it's listing, not that contents of that directory.
The behaviors you describe all follow from that:
ls -d showing . is showing the directory you're in -- the default target of ls with no arguments given.
ls -d */ tells your shell to run ls with each directory under the current one passed as an argument; ls -d then shows the entries for each of its arguments, behaving as you report.
ls -d * tells your shell to run ls with each entry in the current directory passed as an argument. ls then lists one entry for each such argument, not showing the contents of each argument which is a directory name as it otherwise would.
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
Hi i worked on Linux server , and was running this command mv matter/*/* .
but instead i have typed this mv matter /*/* .
because of which some errors starts coming on the screen , and then i was not able to login and when we reboot the server its not coming up.
so can you please tell me what this command has done mv matter /*/* .
You can find out for yourself by inserting an echo at the beginning of the command line:
echo mv matter /*/* .
The expanded command looks like this:
mv matter /bin/ash /bin/bash /bin/echo /bin/false [...] /home/yourname [...] .
All files and directories from the top-level directories (echo /*/) have been moved to this one directory where you executed that command. It's hard to separate them from there, but you can try using a rescue CD:
move all executable files to /bin
make /sbin a symlink to /bin
move all files that look like configuration files to /etc
But since you couldn't find out for yourself what the mv command was doing exactly, you should rather ask someone who knows to fix it for you. It's a lot of work, though.