‘rm -r *’ and Other Linux Command Line Gotchas – InApps is an article under the topic Software Development Many of you are most interested in today !! Today, let’s InApps.net learn ‘rm -r *’ and Other Linux Command Line Gotchas – InApps in today’s post !

Read more about ‘rm -r *’ and Other Linux Command Line Gotchas – InApps at Wikipedia

You can find content about ‘rm -r *’ and Other Linux Command Line Gotchas – InApps from the Wikipedia website

It has been said that the Linux command line is cryptic and difficult to learn. But I’d call it comprehensive. Like anything else, you need to know a few fundamentals to get started putting the system to work doing important computing jobs. The Linux command line is very powerful. Of course, with that power comes user responsibility and the potential to do harm. Knowing what to do is important, but so is knowing maybe what not to do.

Don’t let it intimidate you. That’s just the way it is.

In my Embrace the Linux Command Line post a few months back, we discussed a few commands you could type into a terminal window on a Raspberry Pi. Linux being ubiquitous, you can do the same thing on a notebook, desktop or server. For that matter, the command-line works great if you remotely use it without a window manager and windows over a network connection.

Today we’ll explore a couple of areas you should be aware of that will help you make good command-line decisions.

The Infamous rm Command

You’ve probably heard of the rm command. rm removes files from the system. It is an extremely powerful command and should be treated with appropriate respect.

Like other Linux programs, rm has a handful of command-line options. Type “rm –help” to get a listing.

rm –help command output

A particularly notorious rm usage is with the -R option and an “*” for the file names. It has caused much heartache among system administrators.

The –R option orders rm to travel down into the sub-directories. The * means match ALL files that it finds. You can easily get rid of a lot of files, very quickly, this way. It’s particularly unsettling if you execute the command at the top-level (/) directory as the root user, which has god-like powers on a Linux system.

Suppose you were a busy, somewhat inexperienced system administrator doing some clean up on a Sun Unix machine. That was me, logged in as root, many moons ago. I was flipping around through the directories getting rid of old log files and cleaning out unused files when it happened.

Read More:   npm’s Private Modules are a Hosted Option for Node.js Developers – InApps 2022

Somehow I had issued a cd / to take me up to the topmost directory. I must have been distracted because I thought I was still in the log directory. About three seconds after typing “rm -R *” and hitting enter, I realized my error. It was too late.

About a minute later I heard grumbling from the two users I knew were on the machine. It was a small ComputerVision — Sun Microsystems Unix-based CAD graphics system, so the real damage came from the tool designers losing the changes they had made to their CAD models that morning. It happens. Most every Unix or Linux system administrator has made a similar snafu.

Needless to say, I had to spend the remainder of the day and that night rebuilding the system from tape and backups. I had backups of the user data from the previous day so we lost maybe four hours of production work. The tool designers also had to do other work while I repaired their system. More lost production time, now for two people. I was in the doghouse for a little while after that one.

Fortunately, as a regular user, you aren’t likely to wipe out your machine with the rm command. You can remove your own files inadvertently, though, so always make sure you know where you are in your directory structure. And, use the “rm -R *” combination sparingly with rm.

It might be instructional to burn a micro-SD with Raspbian Linux and put it in a Raspberry Pi. Then execute “rm -R *” at the / directory as root, to see what happens. You can always just re-burn the micro-SD to get a new system back again. Might as well get the worst over with and out of the way.

Disk Full Scenario

A typical time when you might run into trouble with rm is when your disk is or almost full and you have to scramble to clear out some files. Sometimes you’ll get a message in a terminal saying you are out of disk space. The machine might not crash when you fill up the disk. So, you probably have a little time to get rid of some files and reclaim some space.

We can find out the status of the disk with the df command.

df command output

I like to use the -h command-line option so I can see the file space sizes in mega and gigabytes.

There is a 750GB disk in my antique ASUS Linux notebook. You could just use the whole disk for your computer, although I like to divide it into “partitions.” Partitions break up the disk space and associate each section with a /dev name. That way I can have the Linux operating system and applications in one partition and my user files in another partition. When I periodically upgrade to a new version of Linux, I just reformat the root (/) directory and copy a new Linux image on top of it. This has no effect on user files out in the /home directory. I associate the /dev/sda1 partition with the / directory. The /home directory is tied to the /dev/sda5 partition.

Read More:   Donald Knuth on Machine Learning and the Meaning of Life – InApps 2022

Looking at the df listing above we can see that the root file system (/) is /dev/sda1 and is sized at 92GB. I’ve only used 35GB for the operating system and applications, which is about 40% of the total partition space. There are about 53 GB still available for more system and application files.

Further down in the listing is the /dev/sda5 partition, associated with the /home directory. If you see the use percentage up above 95%, it might be time to delete unused files or move some of them into another partition or onto an external archive drive.

Copying And Moving Files

The cp command copies files from one place to another. mv moves files around.

Using both are pretty straightforward. Here are a couple of examples.

linux-notebook% cp rob.txt test.txt

linux-notebook% mv rob.txt test.txt

The first one copies one file to a new name. The second one renames the rob.txt to test.txt.

You can also copy and move directories. Say you have a directory named rob1. Under rob1 you have a file named test.txt. You can copy the directory and the file to a new directory. You’ll have to use the -r option to go down into the directory and copy the file located there as well.

linux-notebook% cp -r rob1 rob2

Now there will be a directory named rob1 with the test.txt file, as well as, a directory named rob2 with a test.txt file.

What happens if we issue an “mv rob1 rob2″?

Linux will move the rob1 directory right over to rob2. That removes the rob1 directory. Oh, and it overwrites whatever is in rob2, if it already exists. Linux won’t ask you if you want to overwrite the directory. It will just go ahead and do what you tell it to do.

We kind of get back to that user responsibility thing with mv, so again, be cognizant of where you are in the directory tree and what you want to actually do with your files.

Wrap Up

The Linux command-line is a powerful tool for all types of computing jobs. It is a little dangerous because there aren’t a lot of safeguards built-in to keep you out of trouble.

Knowing about some of the pitfalls will help you make good command-line decisions. Mistakes will be made and it’s just part of the learning process. Stick with it and move forward. Sometimes it takes a little while. Linux is very comprehensive.

Read More:   A Reusable Code of Conduct for Companies Building Open Source Projects – InApps Technology 2022

Feature image by TeeFarm from Pixabay.

Source: InApps.net

List of Keywords users find our article on Google:

rm -rf *
linux administrator jobs
unix system administrator jobs
linux system administrator jobs
unix administrator jobs
linux admin jobs
unix administrator job
hire linux system administrators
rm -rf * command
rm -f linux
linux consultant jobs
part time linux system administrator vacatures
unix system administrator job
unix system manager jobs
linux system administrator job
hire linux developers
myembrace
r m industries
tape command
read a file linux command line
find -exec rm
wawa customer service associate
system administrator linkedin profile
linux commands wikipedia
mv command works linkedin
wipeout wikipedia
linux wikipedia
rm r
r/flipping
vacatures part time linux system administrator
linux outsourcing
part time unix system administrator vacatures
vacatures part time unix system administrator
linux technical consultant jobs
full-time unix system administrator vacatures
unix linux system administrator jobs
unix linux administrator jobs
r linux
rm tech
rm developers
linux systems administrator jobs
rm help
rm custom homes
read linux command
rm -rf linux
what is /dev/sda1
raspberry pi wikipedia
asus linux
systemback windows
command in linux
rm -rf command
/dev/sda5
filespace
office partition hire
rm group services
linux copy directory to another directory
linux cp
cp *.txt
linux rm -rf *
rm -f command line
rm -f vs rm -rf
x-files wikipedia
wikipedia wipeout
find rm
good morning vietnam wiki
snyk cli
requirements-dev.txt
linux rm help
wikipedia linux
raspberry pi remove directory with files
rm *
rm icons
remote linux system administrator jobs
linux server administrator jobs
linux system administrator remote jobs
rm tool hire
linux system admin jobs
onefile jobs
quarkus course
vacatures full-time linux system administrator
cryptic command
how many gigabytes is wikipedia
full-time linux system administrator vacatures
onefile portfolio
r/productivity
cli rm
crossbrowsertesting local connection
crucial partition manager
wawa h st
cognizant github
remote linux administrator jobs
pegas r
root industries type r review
linux remote jobs
linux sysadmin jobs
raspberry pi cad software
hard disk 750gb
raspberry wikipedia
remote linux admin jobs
linkedin summary examples for system administrator
hire linux administrator
raspbian github
cognizant wikipedia
partition take on me
cmd recruitment
cleaning jobs offshore
eve online raspberry pi
mv line group
rm in r
command product line
linux read command
hire a linux developer
linux rm -rf
at command in linux
rm recruit
txt rm
niche partitioning
at command linux
disk related commands in linux
linux rm -f
rm -rf linus
command at linux
in linux command
dna rm
linux if command
raspberry pi cad
teams lineworks
very cryptic command
eve online linux
sda1 linux
unix clear directory
linux move files from one directory to another
move directory linux
back that thang up clean
bash remove all files in directory
linux read file line by line
root file system full in linux
who linux command
linux systems administrator job
linux file command
linux for command
move directory windows command line
rob2
rscript linux
linux command |
command line
Rate this post
As a Senior Tech Enthusiast, I bring a decade of experience to the realm of tech writing, blending deep industry knowledge with a passion for storytelling. With expertise in software development to emerging tech trends like AI and IoT—my articles not only inform but also inspire. My journey in tech writing has been marked by a commitment to accuracy, clarity, and engaging storytelling, making me a trusted voice in the tech community.

Let’s create the next big thing together!

Coming together is a beginning. Keeping together is progress. Working together is success.

Let’s talk

Get a custom Proposal

Please fill in your information and your need to get a suitable solution.

    You need to enter your email to download

      Success. Downloading...