The title pretty much explains what I want to accomplish. I was able to accomplish half the task which was to summarise all the files which were of type ASCII in my Home directory but not able to accomplish the other half which was to remove those files.
mohit#dell3568:~$ ls | xargs -n 1 -I{} file {} | grep ASCII | cut -f1 -d ":" | xargs -n 1 -I{} rm -i {}
rm: remove regular file 'a'? rm: remove regular file 'adfasdf'? rm: remove regular file 'asdf'? rm: remove regular file 'auto-remove-NON_REMOVED'? rm: remove regular file 'BIGGEST_PACKAGE'? rm: remove write-protected regular file 'config_DOT_dpkg-new.bak'? rm: remove regular file 'CutCommandInLinuxPrac'? rm: remove regular file 'duplicateTorrentFilesInTorrentTwoFolderUnderTheCompleteWebDevCourse.txt'? rm: remove regular file 'etc_mono_config.bak'? rm: remove regular file 'FileForGrepPrac'? rm: remove regular file 'FolderView.qml.bak---Copied_as_I__made_changes_----590and607LinesAreChanged.bak'? rm: remove regular file 'GRUB_EaSy_22'?
I wasn't able to delete the files as it was not giving the option to select 'yes' or 'no'. Thanks for any help.
rm: remove regular file 'headTestFileDelMeLater'?
rm: remove regular file 'historyOUT.txt'?
rm: remove regular file 'JavaForLogRead.java'?
rm: remove regular file 'online-terminal-PS1'?
rm: remove regular file 'packagesSize.txt'?
rm: remove regular file 'TableExample'?
rm: remove regular file 'TankGame'?
rm: remove regular file 'VeryImpUSEFULcommandsLINUX'?
rm: remove regular file 'Xresources'?
Related
I have a .git/ folder that I'd like to delete. However, it isn't possible because there is a puzzling file into it which is not reachable.
Below is my try:
$ rm -rf .git/
rm: cannot remove '.git/': Directory not empty
$ rm -r .git/
rm: descend into directory '.git/'? y
rm: cannot remove '.git/t8QVta1': No such file or directory
rm: remove directory '.git/'? y
rm: cannot remove '.git/': Directory not empty
$ ls -l .git/
ls: cannot access '.git/t8QVta1': No such file or directory
total 0
?????????? ? ? ? ? ? t8QVta1
$
I have no idea what is the 't8QVta1' file and all of the question marks.
Many thanks for your help.
The ?????????? ? ? ? ?... output of ls may indicate that you are missing the correct permissions to access this file. If this is the problem, you could try giving yourself permissions over the parent directory and its children with the following command:
sudo chmod -R g+x .git/
To remove a non-empty folder use -rf flags
$ rm -rf .git
I'm trying to run a command called bedtools shuffle on a file 5 times and save each run as with its counter after the filename (i.e. SHUFFLE1... SHUFFLE 5).
Here is my code but I keep getting the error message below:
for i in {1..5}; do bedtools shuffle -i '/PATH/wgEncodeBroadHistoneOsteoblH3k27acStdPk.broadPeak_use' -g '/PATH/chrom.sizes'> rm -f '/PATH/wgEncodeBroadHistoneOsteoblH3k27acStdPk.broadPeak_use_SHUFFLED${i}.bed'; done
-bash: rm: cannot overwrite existing file
-bash: rm: cannot overwrite existing file
-bash: rm: cannot overwrite existing file
-bash: rm: cannot overwrite existing file
-bash: rm: cannot overwrite existing file
Please advise!
I want to rm or cp a bunch of files with common extensions, some of them start with a - and so unix complains about unknown options. What can I do?
rm *csv
man rm:
To remove a file whose name starts with a '-', for example '-foo',
use one of these commands:
rm -- -foo
rm ./-foo
So:
$ touch -- -test test
$ rm -- *test
rm: remove regular empty file 'test'? y
rm: remove regular empty file '-test'? y
$
Also, quoting works to inhibit globbing if there's, say, a literal asterisk in the name:
rm "*cvs"
Sometimes it might be useful to use the interactive option and confirm the file you want to delete:
rm -i -- *
This is handy if filenames have characters hard to type on your keyboard.
ATTN: shell gods ;)
I can't seem to figure out how to delete a file with a unicode character 0x2400 in the filename on OSX (Example: ␀.test).
It's not a NULL character per-se, but a "symbol for null". (See: http://unicodelookup.com/#null/1)
Script - How to Reproduce
#!/usr/bin/env bash
dir="${HOME}/test_dir"
# Create Directory: ~/test_dir
if [ ! -d "${dir}" ]; then
printf "\nCreating Directory: ${dir}\n"
mkdir ${dir}
fi
# Create our character
char=$'\xE2\x90\x80'
# Create filename
file="${dir}/${char}.test"
# Create the File
printf "\nCreating File: ${file}\n"
touch ${file}
Delete the file... NOPE!
# Attempt 1 - Delete File
printf "\nDeleting File: ${file}\n"
rm -rf ${file}
Delete the whole directory... NOPE!
# Attempt 2 - Delete Directory
printf "\nDeleting Directory: ${file}\n"
rm -rf ${dir}
Delete the file via inode... NOPE!
# Attempt 3 - Delete File
inode=$(ls -i1 ${dir} | awk '{print $1}')
printf "\nDeleting via Inode: ${inode}\n"
find ${dir} -inum ${inode} -exec rm -i {} \;
The whole script should output something like this:
Creating File: /Users/bsmith/test_dir/␀.test
Deleting File: /Users/bsmith/test_dir/␀.test
rm: /Users/bsmith/test_dir/␀.test: Invalid argument
Deleting Directory: /Users/bsmith/test_dir/␀.test
rm: /Users/bsmith/test_dir/␀.test: Invalid argument
rm: /Users/bsmith/test_dir: Directory not empty
Deleting via Inode: 68592933
remove /Users/bsmith/test_dir/␀.test? y
rm: /Users/bsmith/test_dir/␀.test: Invalid argument
This command works for me:
rm ?.test
But sadly it is very probable that it will NOT work for you.
It is a known bug of osx:
Is it impossible to delete/move a file named “␀” on mac?
Rename folder with odd characters
The sure bet is to boot from a pen drive with some Linux OS, mount the file system in such Linux, and erase the file. It is sure that files with such names could be erased in Linux.
On Windows I am trying to add a Makefile target to remove all files from a specific directory (NOT including subdirectories)...
clean_files:
rm -f Build/*.*
But I get the error: /bin/sh: rm: command not found
Running it from the command line works and running it without the *'s works.
clean_files:
- rm -f Build/*
putting a '-' before a make command will ignore any errors from that command, like
rm: cannot remove `Build/subdir': Is a directory
For removing all files from directory (NOT including sub-directories) consider:
clean_files:
find Build/ -type f -maxdepth 1 -delete