The reason this occurs is because bash actually expands the asterisk to every matching file, producing a very long command line.
Try this:
find . -name "*.pdf" -print0 | xargs -0 rm
Warning: this is a recursive search and will find (and delete) files in subdirectories as well. Tack on -f
to the rm command only if you are sure you don’t want confirmation.
You can do the following to make the command non-recursive:
find . -maxdepth 1 -name "*.pdf" -print0 | xargs -0 rm
Another option is to use find’s -delete
flag:
find . -name "*.pdf" -delete
Related Posts:
- How do I grep recursively?
- How do I grep recursively?
- How do I grep recursively?
- How do I use grep to search the current directory for all files having the a string “hello” yet display only .h and .cc files?
- SSH using python script
- How can I exclude directories from grep -R?
- How can I exclude directories from grep -R?
- Difference between using “chmod a+x” and “chmod 755”
- How to cat <
> a file containing code? - Extract file basename without path and extension in bash
- Given two directory trees, how can I find out which files differ by content?
- Diff command along with Grep gives “Binary file (standard input) matches”
- How to download a file from server using SSH?
- What is the difference between “#!/usr/bin/env bash” and “#!/usr/bin/bash”?
- What does `set -x` do?
- Command to change the default home directory of a user
- Using ls to list directories and their total sizes
- What does “&” at the end of a linux command mean?
- Can’t remove a directory in Unix
- Syntax error near unexpected token ‘then’
- C fopen vs open
- Restarting cron after changing crontab file?
- How do I write stderr to a file while using “tee” with a pipe?
- cd into directory without having permission
- Copying a large directory tree locally? cp or rsync?
- Can I nohup/screen an already-started process?
- Environment variables of a running process on Unix?
- In my /etc/hosts/ file on Linux/OSX, how do I do a wildcard subdomain?
- When does /tmp get cleared?
- SSL Certificate Location on UNIX/Linux
- Is it possible to detach a process from its terminal? (Or, “I should have used screen!”) [duplicate]
- What does ‘set -e’ do, and why might it be considered dangerous?
- Meaning of directories on Unix and Unix like systems
- How to remove empty/blank lines from a file in Unix (including spaces)?
- How to forcibly close a socket in TIME_WAIT?
- How can I rename a Unix user?
- How to get pid of just started process
- Can you have more than one ~/.ssh/config file?
- How to disable everything in crontab -l?
- How to sort ps output by process start time?
- Why does ENOENT mean “No such file or directory”?
- Why do you need to put #!/bin/bash at the beginning of a script file?
- error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’ — Missing /var/run/mysqld/mysqld.sock
- “E: Unable to locate package python-pip” on Ubuntu 18.04 [duplicate]
- -bash: syntax error near unexpected token `newline’ for display command
- Changing the resolution of a VNC session in linux
- Building HelloWorld C++ Program in Linux with ncurses
- Pseudo-terminal will not be allocated because stdin is not a terminal
- tar removing leading ‘/’ from member names
- Directory Inode vs Regular File Inode
- Opening a .tar.gz file with a single command
- How to make and apply SVN patch?
- can’t remove python pip
- How would I get a cron job to run every 30 minutes?
- How to automatically redirect HTTP to HTTPS on Apache servers?
- connect to host localhost port 22: Connection refused
- Implementing shell in C and need help handling input/output redirection
- Can you Run Xcode in Linux?
- Telnet [Unable to connect to remote host: Connection refused]
- Implementation of multiple pipes in C
- chmod: changing permissions of ‘my_script.sh’: Operation not permitted
- Terminal Multiplexer for Microsoft Windows – Installers for GNU Screen or tmux
- Gedit command not working in kali linux terminal
- Curl : connection refused
- How to install Android SDK on Ubuntu?
- make -j 8 g++: internal compiler error: Killed (program cc1plus)
- How can I use grep to show just filenames on Linux?
- Bash script prints “Command Not Found” on empty lines
- Bash export command
- How to edit gitignore file
- Linux Bash: Move multiple different files into same directory
- Adding a new entry to the PATH variable in ZSH
- how to search for a directory from the terminal in ubuntu
- How to use dos2unix?
- How to add a default include path for GCC in Linux?
- How to configure both webserver and appserver for WordPress CMS?
- How to remove all plugins, posts, pages, and inactive themes in one line with wp-cli? WordPress bloatware removal
- Communcation with wordrpess and linux server [closed]
- Anyone else experiencing high rates of Linux server crashes during a leap second day?
- What permissions should my website files/folders have on a Linux webserver?
- Can I automatically add a new host to known_hosts?
- How can I run Debian stable but install some packages from testing?
- Shell command to monitor changes in a file
- Meaning of the buffers/cache line in the output of free
- How to cd into a directory with this name “-2” (starting with the hyphen)?
- how to disable SSH login with password for some users?
- Difference in sites-available vs sites-enabled vs conf.d directories (Nginx)?
- Disk full, du tells different. How to further investigate?
- Filename length limits on linux?
- best way to clear all iptables rules
- How can I port forward with iptables?
- Why do we use a OS Base Image with Docker if containers have no Guest OS?
- How to re-order windows, change the scroll shortcut, and modify the status bar contents in GNU Screen?
- How to prevent a user from login in, but allow “su – user” in Linux?
- I have a keypair. How do I determine the key length?
- Why drop caches in Linux?
- swap partition vs file for performance?
- Best way to disable swap in Linux
- How can I zip/compress a symlink?
- How to find the physical volume(s) that hold a logical volume in LVM