The -r flag: recursive, reverse or raw?
Does -r mean recursive? Often, not always. See what -r and -R really do in rm, cp, ls, grep, chmod, tar, xargs and read on Ubuntu, and the typos that hurt.
What does the -r flag mean?
The -r flag often means recursive: work on a directory and on everything inside it. That holds for rm, cp, grep, scp and rsync. It is not a rule, though. On ls and sort, -r means reverse. On chmod it is a permission mode. On the bash builtin read it means raw input.
A second trap sits next to the first. Some commands spell recursive only as capital -R and give lowercase -r a different job. chmod -R changes a whole tree. chmod -r removes read permission from the files you name, and nothing below them changes.
The -r and -R flags, command by command
This is the short answer for each command. It comes from the Ubuntu 26.04 man pages, plus the 24.04 page where the two releases differ. The sections after the list explain the cases that cause damage.
rm -r: recursive.-r,-Rand--recursiveare the same option.cp -r: recursive. GNUcplists-r,-Rand--recursiveas one option.ls -r: reverse the sort order. Recursive isls -R.sort -r: reverse the output.sort -Ris random order, so neither case means recursive.grep -r: recursive, following a symlink only if you name it on the command line.grep -Rfollows every symlink.chown -R: recursive. The man page lists no lowercase-r.chmod -R: recursive.chmod -ris a mode that removes read permission.tar -r: append files to an existing archive. tar already recurses into directories by default.uname -r: print the kernel release.xargs -r: do not run the command when the input is empty.read -r(bash builtin): keep backslashes as plain characters.useradd -r: create a system account.useradd -Rsets a chroot directory.curl -r: fetch only a byte range of a file.scp -r: recursive, and it follows symlinks inside the tree.rsync -r: recursive.rsync -Rmeans relative paths.
Which coreutils does your Ubuntu run?
On Ubuntu 26.04 the core utilities come from the rust-coreutils package, a Rust rewrite also called uutils. As of December 2026 the 26.04 package is version 0.10.0. The move is not complete on 26.04. Because of unresolved bugs, cp, mv and rm there are still the GNU versions. Ubuntu 26.10 moved those three to uutils as well. Ubuntu 24.04 ships GNU coreutils 9.4 for all of them. On 26.04 the GNU tools also stay available under a gnu prefix, so gnuls runs GNU ls. The Rust rewrites in Ubuntu's base system covers why the switch happened.
This matters for one reason. The flag letters in this guide are the same in both implementations, but the error messages are not always the same. So a script should check the exit status and the files on disk, never the text of a message. To see which implementation answers on your box, compare the first line of each:
ls --version | head -n 1
rm --version | head -n 1ls, sort, chmod, chown and uname are coreutils. grep, tar, xargs, useradd and bash are separate packages, so the uutils move does not touch them.
Commands where -r and -R both mean recursive
rm -r
Without a recursive option, rm does not remove directories. -r, -R and --recursive are one option, and it removes a directory together with its contents. The one other rm option for directories is -d, which removes empty directories. If you ran rm -r on the wrong path, read how to recover files deleted with rm -rf before you do anything else on that server.
cp -r and cp -R
GNU cp treats -r, -R and --recursive as one option, so on Ubuntu there is no difference between cp -r and cp -R. During a recursive copy, GNU cp does not follow symlinks in the source by default. A link in the source tree arrives in the copy as a link. The GNU manual still warns that -r is not portable for copying symbolic links or special files, because on some non-GNU systems -r follows links and copies the contents of special files. In a script that may run on other systems, write -R. How symlinks and ln -s work explains the difference between copying a link and copying its target.
grep -r vs grep -R: the symlink difference
grep has both letters, and they differ in one way. grep -r reads all files under each directory, but follows a symbolic link only if that link is on the command line. grep -R follows all symbolic links, including the ones it meets inside the tree.
Picture a project directory that holds a link to a large data directory somewhere else. grep -r pattern project skips what the link points to. grep -R pattern project searches it, which can mean a much longer search and matches from outside the project. Use -r by default. Use -R when you want the links followed.
Commands where only capital -R is recursive
chown -R
chown -R changes the owner of a whole tree. The man page lists no lowercase -r, so do not count on it. By default chown -R does not traverse symlinks to directories. -H and -L change that. Changing a file's owner to another user needs root.
ls -R and ls -r
ls -R lists the contents of every directory below the one you name. ls -r reverses whatever sort order is active, so a plain ls -r lists names in reverse alphabetical order.
chmod -R vs chmod -r
This pair causes the most damage. chmod -R changes modes recursively. chmod -r is not an option at all. chmod reads it as a symbolic mode, the same kind as u+x or go-w. The r is the read bit and the - removes it. The uutils chmod in 26.04 accepts modes that start with - on purpose, for GNU compatibility, so the command is not rejected as an unknown option.
The mode names no u, g, o or a. The GNU man page on 24.04 gives the rule for that case: the change applies as if a (all) were given, except that bits set in your umask are not affected. The umask is the mask of permission bits your shell leaves off new files. With the common umask 022, no read bit is masked, so chmod -r removes all three read bits. With umask 077, the group and other bits are masked, so only the owner's read bit goes. The GNU chmod source (version 9.7) and the uutils source (0.10.0) both treat that second case as a failure, because a bit that would have been removed under umask 0 was kept.
So a typo of chmod -r mydir for chmod -R mydir changes the directory itself, not the files inside it. A directory you cannot read is a directory you cannot list. What each permission bit means on files and directories shows the effect in a long listing. If the file had the usual 644 or 755 mode before, chmod a+r puts the read bits back.
When you really want to remove read permission, name who loses it: chmod a-r file or chmod o-r file. With an explicit a, the umask rule does not apply, and nobody reading the command later wonders whether you meant -R. Numeric and symbolic chmod modes covers the full syntax.
One warning for testing: root passes read permission checks because of the CAP_DAC_OVERRIDE capability. As root, cat still reads a file after chmod -r. Test the effect as a normal user.
Commands where -r has nothing to do with directories
sort -r and sort -R
sort -r reverses the output. sort -R (--random-sort) shuffles the lines into random order. Neither one is recursive.
tar -r: append to an archive
tar -r (--append) adds files to the end of an existing archive. Its arguments mean the same as for -c. tar does not need a flag to recurse, because it recurses into directories by default. GNU tar cannot modify a compressed archive, so -r works on a plain .tar file, not on a .tar.gz.
uname -r: the kernel release
uname -r prints the kernel release. It is not the Ubuntu release. For that, read /etc/os-release. Inside a container, uname -r reports the host's kernel, because every container on a machine shares that machine's kernel.
xargs -r: skip the command on empty input
Normally GNU xargs runs the command once even if there is no input. With -r (--no-run-if-empty), it does not run the command when standard input holds nothing but blanks. This matters in pipelines such as find ... | xargs rm, where an empty list should mean no action. POSIX.1-2024 specifies -r for xargs as well.
read -r: raw input in bash
read is a bash builtin. Without -r, a backslash in the input acts as an escape character and is removed. With -r, the backslash stays part of the line, and a backslash at the end of a line is no longer a line continuation. Use read -r whenever you read file names or paths. Because read is a builtin, look it up with help read or in man bash.
useradd -r: a system account
useradd -r (--system) creates a system account. It gets no password aging information in /etc/shadow, and its ID comes from the SYS_UID_MIN to SYS_UID_MAX range. useradd -r does not create a home directory, whatever CREATE_HOME says. Add -m if the service needs one. Capital useradd -R is unrelated: it is --root, which applies the change inside a chroot directory.
Network copy tools: curl -r, scp -r and rsync -R
curl -r is --range. It fetches only a byte range, such as curl -r 0-99, from an HTTP, FTP or SFTP server or a local file. Many HTTP servers do not support ranges, and then curl gets the whole document instead.
scp -r copies whole directories recursively. It follows symbolic links that it meets in the tree, unlike GNU cp. So a link to a large directory gets copied as full content. scp -R has nothing to do with recursion. It changes how a copy between two remote hosts is routed.
rsync -r copies directories recursively, and rsync -a already includes it, since -a equals -rlptgoD. rsync -R is --relative: it sends the full path names you typed, so the directory structure from the command line is rebuilt at the target.
Check the -r flags on your own server
Run this block as your normal user, not as root, because root skips the read check in the chmod step. It builds a scratch tree under /tmp with one symlink that points out of the tree.
mkdir -p /tmp/rflag && cd /tmp/rflag
mkdir -p tree/sub outside
echo needle > tree/sub/a.txt
echo needle > outside/b.txt
ln -s ../../outside tree/sub/linkgrep. The first count should be 1, only tree/sub/a.txt. The second should be 2, because -R follows tree/sub/link into outside.
grep -r needle tree | wc -l
grep -R needle tree | wc -lcp and rm. The copied link should still be a link. The plain rm should fail with a non-zero exit status and leave the directory in place. The rm -r should remove it.
cp -r tree copy-r
test -L copy-r/sub/link && echo "still a symlink"
rm copy-r; echo "exit: $?"
test -d copy-r && echo "copy-r is still there"
rm -r copy-r; echo "exit: $?"
test -e copy-r || echo "copy-r is gone"ls and sort. Both of these reverse. Neither one descends into a directory.
printf '%s\n' b a c | sort -r
ls -r tree/sub
ls -R treechmod. The umask 022 line lasts only for this shell. By the rule above, all three read bits go, so ls -l should show only the owner's write bit, and cat should fail with a non-zero exit status. After chmod a+r, the mode should read -rw-r--r-- again.
umask 022
echo secret > f.txt
chmod 644 f.txt
chmod -r f.txt; echo "exit: $?"
ls -l f.txt
cat f.txt > /dev/null; echo "exit: $?"
chmod a+r f.txt
ls -l f.txttar. The listing should show both files, because -r appended the second one to the archive.
tar -cf demo.tar tree/sub/a.txt
tar -rf demo.tar outside/b.txt
tar -tf demo.tarxargs. The first line should print ran once. The second should print nothing.
printf '' | xargs echo ran
printf '' | xargs -r echo ranread. Without -r the backslash disappears, so the first line prints C:temp. With -r it prints C:\temp.
printf '%s\n' 'C:\temp' | { read line; printf '%s\n' "$line"; }
printf '%s\n' 'C:\temp' | { read -r line; printf '%s\n' "$line"; }uname and useradd. The useradd step needs sudo. id should show the new account, and no home directory should exist for it.
uname -r
grep PRETTY_NAME /etc/os-release
sudo useradd -r rflagsvc
id rflagsvc
test -d /home/rflagsvc || echo "no home directory"
sudo userdel rflagsvcClean up when you are done:
cd / && rm -r /tmp/rflagEvery check above looks at an exit status or at files on disk. None of them matches on message text, because messages differ between GNU and uutils.
Read man before you trust a letter
The same letter changes meaning from one command to the next, and sometimes from one case to the other. Before you run a flag you are not sure of, read man <command> or <command> --help. For a bash builtin such as read, use help read.
FAQ
Does -r always mean recursive in Linux?
No. -r means recursive for rm, cp, grep, scp and rsync. It means reverse for ls and sort, append for tar, kernel release for uname, no run on empty input for xargs, raw input for bash read, and a system account for useradd. For chown and chmod, recursive is capital -R only.
What is the difference between cp -r and cp -R?
On Ubuntu there is none. GNU cp lists -r, -R and --recursive as one option, and it copies symlinks in the source as symlinks by default. The GNU manual warns that -r is not portable for symlinks and special files, because some non-GNU systems follow links with -r. Write -R in scripts that may run elsewhere.
Why did chmod -r not change my folder recursively?
chmod -r is a mode, not an option. It removes the read bit from the files you name, limited by your umask, and it does not descend into the directory. The recursive option is capital -R. If the directory had a normal 755 mode before, chmod a+r restores its read bits.
What is the difference between grep -r and grep -R?
Both search directories recursively. grep -r follows a symbolic link only when you name it on the command line. grep -R follows every symbolic link it meets in the tree, so it can search files outside the directory you gave it.
What does read -r do in bash?
It stops backslash from acting as an escape character, so the backslash stays part of the line. Without -r, C:\temp is read as C:temp. read is a bash builtin, so its documentation is in help read or man bash.