Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [rm]

rm is the command to remove files

0
votes
1answer
54 views

Restrict a Specifc Command [duplicate]

I want to restrict "rm" command to user who have a sudo access. example: bob ALL=(ALL) NOPASSWD:ALL I have given SSH Access to"bob". i want to restrict "bob" to run "rm" command. Even though if ...
-1
votes
3answers
165 views

How to use grep and/or awk to select multiple pathnames in file and remove those files?

I have some output that is formatted like so: foo: /some/long/path_with_underscores-and-hyphens/andnumbers1.ext exists in filesystem foo: /another/one.ext exists in filesystem bar: /another/path/and/...
-9
votes
1answer
5k views

Is there a difference between rm -rf / and rm -rf *.*?

Will rm -rf *.* corrupt your filesystem while rm -rf / will not do this?
2
votes
1answer
37 views

wierd chars in command output after RHEL upgrade to 7.3

I am using SuperPutty on Windows 10 to connect to the recently Upgraded RHEL server (from 6.X to 7.3 Maipo). One of my friends is getting strange â character in the output of the rm command after ...
1
vote
1answer
57 views

removing a directory

I'm trying to remove a directory called cc by running the command rm -rf cc, but it has trouble removing a file inside the directory. I get the following error: rm: cannot remove 'boy.mp4' : Input/...
-1
votes
2answers
411 views

Find and rm command deleted the files inside the directory and the directory itself

Can you please check this command? It's deleting the files and the current directory itself. Script is run via cron. Directories: /log/dir/ /log/dir/tmp/ Commands in script: find /log/dir/ -mtime +...
-2
votes
2answers
641 views

How to delete files before 1st of previous month

I have a script running on the 1st of each month. On this script I want to delete all files modified before the first of the previous month. For instance. The script will run on the 1st of March. I ...
1
vote
3answers
669 views

Delete folder with invalid character (-encoding)

On my Linux Mint 18.3 installation I had troubles with my locale setting which caused the generation of a folder that has invalid encoding in its name. I would now like to delete said folder but I ...
-2
votes
1answer
2k views

Missing operands - rm command

In the below code, #!/bin/bash sDir=/a/b/c dDir=/d/e/f rDir="$dDir/recent" shopt -s nullglob : rm $rDir/$deviceName* : problem line rm $rDir/$deviceName* shows missing operands without echo ...
2
votes
4answers
196 views

how to remove files that could be with lower/upper case

how to remove files that could be with lower/upper case for example, the file_name could be: STOCK.Repo or Stock.REPO or stOCK.repo or stock.repo ... etc I would run: rm -f $file_name the ...
0
votes
2answers
595 views

remove files on remote machine

this is simple CLI to remove couple file on remote machine ssh 182.2.34.1 "rm -f /etc/yum.repos.d/repo.1 master.er top.fg REPO.l" but only repo.1 file was deleted what is wrong with my syntax
1
vote
2answers
588 views

bash rotation script

I have a directory structure as follows: backup-2018-01-12 backup-2018-01-13 backup-2018-01-14 backup-2018-01-15 backup-2018-01-16 backup-2018-01-17 backup-2018-01-18 backup-2018-01-19 backup-2018-01-...
1
vote
3answers
315 views

Trivial rm -rf command destroys my operating system in a testing machine

I use Bash 4.3.48(1) and I ran the following command pattern on a testing VPS machine: rm -rf ${drt}/${pma}* This command deleted the entire operating system (Ubuntu). That was evident by executing ...
3
votes
4answers
6k views

Delete all directory that begin with a particular string

What command do I have to use to delete all directories that begin with "graphene-80" What can I add to the "rm" command as option?
0
votes
1answer
251 views

How do I compare mlocate.db to what exists now?

I ran rm -rf on /var/cache/lxc, not realizing it was full of symlinks. I've lost a bunch of files, including most of /dev. I have a mlocate.db from 16 hours ago. How do I compare the list of files ...
0
votes
1answer
28 views

A good way to delete all cache dirs of all CMSs under document root with Bash

Say that under document root I have 3 apps; One is WordPress, second is Drupal, and third is Magento. I wonder what's a good way to delete all cache directories of all CMSs under document root. I ...
1
vote
2answers
752 views

What happens when we call rm filename.txt?

Inspired by this post, Do we get more disk space when we call rm insert_filename? The linked UNIX stackexchange post says: "the file gets unlinked. The data is still sitting there on disk, but the ...
0
votes
4answers
1k views

How to delete files starting with # using “rm #*”?

In bash, I want to delete files starting with a #. I tried rm #*, but got message: rm: missing operand. So how to achieve this?
3
votes
1answer
196 views

Use ctime only for weekdays

I have a script to delete all folders created before past 2 days. Now, on Monday, it deletes just every folder from last week, which I do not want. Is there an option to consider only weekdays for ...
0
votes
1answer
74 views

How do I remove a directory on a remote system that has a quota?

I have an rsync.net account that has hit its quota and I'm trying to remove (rm -rf) a directory to clean up space. However all the remove commands I can think of to try (rm, truncate, find -delete, ...
1
vote
2answers
78 views

How do I make this script search through all users home folders and then rm -f the files matching EXT? [duplicate]

How do I make this script search through all users' home folders and then rm -f the files matching EXT? Right now it's only deleting the files matching EXT in the current folder where I am executing ...
0
votes
1answer
100 views

rm -rf destroyed directories of the files set to be deleted (multiple arguments)

In a testing environment I executed: rm -rf /var/www/html/${domain} /etc/nginx/sites-available/${domain} /etc/nginx/sites-enabled/${domain} The result was that html, sites-available and sites-...
0
votes
1answer
1k views

rm: Unable to remove directory <some/sub/directory>: Device busy

Solaris 11.3 My script needs to recursive delete in a directory. Other directories work fine. One directory is plagued by the following: rm -rf: Unable to remove directory <some/sub/directory&...
2
votes
0answers
450 views

File shows up in ls but cannot rm or mv, seems to be held by some unknown process

I do a lot of work on an SGE cluster running CentOS 7, and have recently had issues with jobs dying randomly, but seemingly with some processes still running that prevent me from cleaning up to start ...
0
votes
3answers
205 views

synchronise with remote machine via http, and delete older files

I have a folder in my system(ubuntu) that gets synchronized with work using wget. File-names are in the following format A156.0.1.x, A156.0.y, A156.0.z, A156.0.a, A156.0.b. All files are created at ...
2
votes
3answers
2k views

How to delete all folders in a directory using bash?

Basically, I want to delete all subfolders, but leave all the files intact. For example: Folder1/ randomStuff/ nope.txt installer.jar build.sh I want randomStuff and its files ...
1
vote
3answers
3k views

clear multiple directories with rm

I am trying to clear multiple directories stored in an array. Here's a simplified example (I have more directories). #!/bin/bash $IMAGES_DIR="/Users/michael/scripts/imagefiles" $BACKUP_DIR="/...
1
vote
0answers
40 views

Would cutting & pasting a file to a USB drive be the equivalent of deleting the file? [duplicate]

I've always wondered if cutting & pasting / removing the file from an OS would be the equivalent of taking proper precautions when deleting a file such as using the rm -rf command. I DID read ...
24
votes
1answer
2k views

Since when do the POSIX and GNU rm not delete /?

For several years now, the GNU rm utility won't delete / unless it is called with the --no-preserve-root option. However, the command rm -rf / has been lodged in the collective subconscious as ...
-2
votes
1answer
61 views

Removing certain files in a series of subdirectories

I have a directory that has several subdirectories in it. Each subdirectory has several files in it. I want to delete all the files in the subdirectories except the .pdf ones. And leave the ...
7
votes
3answers
574 views

Are another user's non-empty subdirectories safe from deletion in my directory?

In the following situation ls -alh total 0 drwxrwx--- 1 user http 20 Nov 30 08:08 . drwxrws--- 1 user http 310 Nov 30 08:07 .. drwx------ 1 http http 10 Nov 30 08:08 empty-subdir drwx------ 1 http ...
0
votes
2answers
29 views

Remove files with smallest filename suffixes

I have a directory of files with similar names, but with incrementing digits as a suffix. I want to remove the lower suffixed files and only keep the files with the highest suffix. Below is an ...
1
vote
0answers
147 views

Unable to delete files from within smplayer

smplayer has an option that allows deleting the currently playing video. This worked well in windows 7, and even in debian 9 till about an year back. It brings up a confirmation dialog box, and if I ...
2
votes
2answers
59 views

Delete file with broken name

I've somehow created a file that I can not seem to figure out how to delete via CLI. $ ls -alF total 8195 -rw-r--r--+ 1 me my_group 0 Jul 19 14:10 ''$'\r' drwxrwx---+ 1 system ...
0
votes
1answer
61 views

Remove command in loop

I wold like to know if I issue the command rm -rf */????sample to remove all the files like 0000sample to 9999sample. Is there any possibility that once deleting all the file the command still ...
0
votes
1answer
316 views

How to delete large amount of log files by date (Specifically year)

Wondering how I delete large amount of log files that are ordered by date. Consider the example of having a retention rate of 2 years in a company, how would I go about efficiently and safely ...
0
votes
1answer
344 views

Interactive rm command

When I remove some directories, I often forgot their structure and consequently I don't add the -rf flags when needed. When this happens, rm just returns an error and reminds me that I am trying to ...
2
votes
3answers
176 views

Remove symlinks originating from specific directory

I have an "install.sh" that installs my personal scripts: find /home/Steven -name '*.sh' -exec ln -s -t /usr/local/bin {} + I would like to make an "uninstall.sh" that removes the symbolic links ...
0
votes
1answer
256 views

How to delete a specific set of ??.png files in a directory?

I accidentally extracted an archive containing about a hundred files ??.png where ? is normal ASCII character a - z. Meaning there are two characters and it's PNG pictures. I'd rather learn how to ...
13
votes
4answers
3k views

Deleting specific files based on filename from terminal

I have a directory containing files with names rho_0.txt rho_5000.txt rho_10000.txt rho_150000.txt rho_200000.txt and so on. I would like to delete all those that are a multiple of 5000. I tried ...
1
vote
1answer
270 views

rm -iR does not work inside a loop

Here is my loop ls -ltrd * | head -n -3 | awk '{print $NF}' | while read y; do rm -iR $y done output: rm: descend into directory oct_temp17? rm: descend into directory oct_temp18? rm: ...
0
votes
2answers
54 views

Find and delete files depending on the date the files were copied

It seems like someone from work entered the wrong command, and we ended up having all the files and folders of /etc/ in /home/share(A folder we use for sharing Data amongst users.) It looks like ...
1
vote
2answers
942 views

Delete files older than X days with lastest modified file

Is there is any solution to delete the files based on comparing their modified date with the most recently modified file? The older files need to be deleted with respect to most recent file. For ...
3
votes
4answers
2k views

Delete the parent folder keeping all content [duplicate]

I want to delete my parent directory but keep all of its content. Currently my directory structure $ /usermanagement/usermanagement/file1 After deleting my parent directory I want to see like ...
1
vote
3answers
114 views

Safely Deleting a Directory Only If It ISN'T a Mount Point

Unfortunately I'm being forced to work with a piece of software that handles automatically mounting and unmounting a network volume very poorly; it has an annoying tendency to leave a directory where ...
1
vote
1answer
327 views

How to restrict some commands for admin in Linux(CentOS)

how to restrict some commands for admin in Linux(CentOS) I tried to use visudo in root , and write ABC ALL=ALL,!/bin/rm,!/bin/sudo to restrict the "ABC" user not to remove some important files. ...
0
votes
2answers
39 views

Delete all other undefined directories

I need to create a purge script to remove any foreign directories from a specific list of directories. My idee was to do something like this : #!/bin/ksh find /data/${USER}/SAS/ -type d ! -name '...
0
votes
2answers
946 views

Rm hardlink without removing file/directory itself

Say I create a hardlink with ln x y. Is there a way to remove the link at y without removing the file at x, after I create the link? It looks like I did a rm -rf on y and it deleted x as well, would ...
0
votes
3answers
346 views

Command “sudo rm \\” hangs - want to ensure no damage was done to system

I am trying to figure out what happened. About an hour ago I was editing a file in /root using sudo but when I went to save and quit I accidentally hit the backslash key and wound up with a file in ...
2
votes
0answers
1k views

Unable to remove folder, even with `--force`, sudo not needed

Trying to remove a folder: $ rm -r folder rm: cannot remove 'folder/subfolder/cifscaf6': No such file or directory Doesn't work. Let's try with -f: $ rm -rf folder rm: cannot remove 'folder/...