Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
First thing first, if you really want to mess around please do it using a normal user not as root.
Quote:
rm -r "first inserting line"
'rm -r' will delete directories recursively and that's very dangerous. rm takes filename or directory name as it's argument not contents of a text file. see 'man rm'
Now you need to know about redirection. Check out bash and sed, more specifically 'sed' for your line deletion task but it's really recommended that you get your hands dirty learning bash first.
I too agree that you should use 'root' carefully. A newbie can do major damage with just one slip. Especially when you are using 'rm -r' on something. 'man rm';
Quote:
NAME
rm - remove files or directories SYNOPSIS
rm [OPTION]... FILE... DESCRIPTION
This manual page documents the GNU version of rm. rm removes each specified file. By default, it does not remove directories. If a file is unwritable, the standard input is a tty, and the -f or --force option is not given, rm prompts the user for whether to remove the file. If the response does not begin with `y' or `Y', the file is skipped.
OPTIONS
Remove (unlink) the FILE(s).
-d, --directory unlink FILE, even if it is a non-empty directory (super-user only)
-f, --force ignore nonexistent files, never prompt
-i, --interactive prompt before any removal
-r, -R, --recursive remove the contents of directories recursively
-v, --verbose explain what is being done
--help display this help and exit
--version output version information and exit
To remove a file whose name starts with a `-', for example `-foo', use one of these commands:
rm -- -foo
rm ./-foo Note that if you use rm to remove a file, it is usually possible to
recover the contents of that file. If you want more assurance that the
contents are truly unrecoverable, consider using shred.
You should get in the habit of using the 'man command'.
Quote:
Just a few links to aid you to gaining some understanding;
Something to play with and analyse in combination with man pages:
Code:
user@localhost:~/tmp$ echo line 1 >> testfile
user@localhost:~/tmp$ echo line 2 >> testfile
user@localhost:~/tmp$ echo line 3 >> testfile
user@localhost:~/tmp$ echo line 4 >> testfile
user@localhost:~/tmp$ echo line 5 >> testfile
user@localhost:~/tmp$ head -n -1 testfile
line 1
line 2
line 3
line 4
user@localhost:~/tmp$ head -n -1 testfile > testfile_without_last_line
user@localhost:~/tmp$ cat testfile_without_last_line
line 1
line 2
line 3
line 4
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.