LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 01-06-2013, 08:23 AM   #1
Bouncerman
LQ Newbie
 
Registered: Jan 2013
Location: Roanoke, Virginia
Distribution: Lubuntu 12.1
Posts: 3

Rep: Reputation: 0
CLI commands... was there a faster/better way to do the job?


My History:
Heard of Linux
Bought Redhat 5.0 soon after it hit the shelf
Played with multiple Linux distros
Currently use Lubuntu 12.1

While I am not a complete novice, there is still a lot that I have to learn in Linux. Right now I am choosing to work more in the use of the terminal. I once saw a shirt that had something like...

rm -rf /bin/laden (if you haven't seen it, it is easy to Google it)

I thought it was kind of cute, and decided to make use of the idea; but putting it to a christian theme:

:$ pwd
/home/my/heart
:$ ls
etc EVIL guilt lust unforgiveness
:$ cd EVIL
:$ ls
death etc sin
:$ cd ..
:$ mv etc guilt lust unforgiveness EVIL
:$ rm -rf EVIL
:$ sudo mv /Jesus /home/my/heart
:$ ls
Jesus
:$ cd Jesus
:$ ls
etc eternal life forgiveness love purpose joy peace

Of course the use of cd and ls in this case was mostly to illustrate what I was doing to anyone who might see this, and since I actually did all of this on my computer through terminal; it gave me hands on experience. My question rests mostly in the area of the rm, mv and in real life instances cp. Was there a shorter/simpler way of doing that work? I ask because I have heard that there are sometimes shortcuts to doing things in terminal possibly using pipes (|) etc. I have Googled for answers, but some of the things I have found, I'm not sure I understand, Along with your answer, any valid links would be greatly appreciated.
 
Old 01-06-2013, 09:39 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,504

Rep: Reputation: 3992Reputation: 3992Reputation: 3992Reputation: 3992Reputation: 3992Reputation: 3992Reputation: 3992Reputation: 3992Reputation: 3992Reputation: 3992Reputation: 3992
Quote:
Originally Posted by Bouncerman View Post
Of course the use of cd and ls in this case was mostly to illustrate what I was doing to anyone who might see this, and since I actually did all of this on my computer through terminal; it gave me hands on experience. My question rests mostly in the area of the rm, mv and in real life instances cp. Was there a shorter/simpler way of doing that work? I ask because I have heard that there are sometimes shortcuts to doing things in terminal possibly using pipes (|) etc. I have Googled for answers, but some of the things I have found, I'm not sure I understand, Along with your answer, any valid links would be greatly appreciated.
No, those commands are what's used, and you used them correctly. If you want to know each option of those commands, just type in "man <command name>", such as "man cp", or "man rm".
 
Old 01-06-2013, 10:54 AM   #3
alieblice
Member
 
Registered: Jul 2011
Posts: 80

Rep: Reputation: Disabled
you can use alias commands for repetitive commands.
also learning your shells shortcut can help a lot.
 
Old 01-06-2013, 11:39 AM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,131
Blog Entries: 2

Rep: Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833
While your commands are (almost) syntactically correct they involve also unnecessary steps, like moving directories before deleting them and so on.
I would come up with a shorter version:
Code:
:$ pwd
/home/my/heart
:$ ls
etc EVIL guilt lust unforgiveness
:$ ls EVIL
death etc sin
:$ rm -rf etc guilt lust unforgiveness EVIL
:$ sudo mv /Jesus /home/my/heart
:$ ls
Jesus
:$ ls Jesus
etc eternal life forgiveness love purpose joy peace
For the rm command, you need to use the -r option, since EVIL is a directory.

Last edited by TobiSGD; 01-06-2013 at 11:41 AM.
 
Old 01-06-2013, 02:44 PM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Arch
Posts: 3,077

Rep: Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268
Code:
cd EVIL
ls
cd ..
## same as
ls EVIL
# see coreutils manual: ls invocation
Code:
mv etc guilt lust unforgiveness EVIL

### same effect for given set of files as
## move everything starting with a lowercase to EVIL directory
find . -name '[a-z]*' -print0 | xargs -0 mv -t EVIL
# see findutils manual: Base Name Patterns, Safe File Name Handling
#     coreutils manual: mv invocation
## same as
LC_ALL=C # might be required first
mv [a-z]* EVIL
# see bash manual: Pattern Matching

### same effect for given set of files as
## move everything with a lowercase name to EVIL directory
LC_ALL=C # might be required first
shopt -s extglob # might be required first
mv *([a-z]) EVIL

### same effect for given set of files as
## move everything not called EVIL to EVIL directory
find . ! -name EVIL -print0 | xargs -0 mv -t EVIL
## same as
shopt -s extglob # might be required first
mv !(EVIL) EVIL
Code:
mv etc guilt lust unforgiveness EVIL
rm -rf EVIL

### same effect for given set of files as
## delete everything
rm -rf *
## same as
find . -delete
PS: I don't think "unforgiveness" is a word.
 
Old 01-06-2013, 02:48 PM   #6
Thad E Ginataom
Member
 
Registered: Mar 2011
Distribution: Ubuntu 12.04 with KXStudio, MATE & Compiz
Posts: 46

Rep: Reputation: 7
Well, I don't care for religion --- but I like the way you are finding out about commands by playing with them . It's a great way to go.

It reminds me that I used to name test output files dog. Obviously, because I liked to

$ cat dog

You might like to add the ln command to your learning. Discover how the same file can be accessed by different names
Code:
$ echo bad >devil
$ ln devil pleasing-face
$ rm devil
Enjoy

Last edited by Thad E Ginataom; 01-06-2013 at 02:54 PM.
 
Old 01-06-2013, 06:33 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,295

Rep: Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358
This is a good cli tutorial
http://rute.2038bug.com/index.html.gz

bash in depth
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
Old 01-07-2013, 10:30 AM   #8
Bouncerman
LQ Newbie
 
Registered: Jan 2013
Location: Roanoke, Virginia
Distribution: Lubuntu 12.1
Posts: 3

Original Poster
Rep: Reputation: 0
Thank you to everyone who has jumped in and helped and/or added links. I would have done some responding yesterday, but sinus issues really made a long day.

@TB0ne Yes I have looked at those, but sometimes they don't format well with my brain; though they are helpful.
Quote:
If someone helps you, or you approve of what's posted, click the "Add to Reputation" button, on the left of the post.
I had to look that one up because the scales were not showing, but got it fixed. Thank you!

@alieblice My current understanding of alias is that it is mostly used when you will continue repeating a task. An example might be that when you apt-get something to install it, you could create an alias that would allow you to type for example:
"sudo apt-get application" rather than "sudo apt-get install application".
Quote:
also learning your shells shortcut can help a lot.
Something else I am working on too. Thanks.

@TobiSGD
Quote:
While your commands are (almost) syntactically correct they involve also unnecessary steps, like moving directories before deleting them and so on.I would come up with a shorter version
While my reasoning for moving then deleting was for real life instances nonsensical, I used that as a way to illustrate that those things could be filed as evil, and that they are good to remove. Until you posted though, I thought you had to be inside of the directory to use the ls command on it. Thank you.

@ntubski WOW a lot of great information. Thank you for the added insight on all the ways to do something.
Quote:
## move everything not called EVIL to EVIL directory
find . ! -name EVIL -print0 | xargs -0 mv -t EVIL
This is my absolute favorite of those because it still reflects what I want to show and does the job.
Quote:
never say "for obvious reasons" for obvious reasons ;-)
Good point, because what may be obvious to one person may not be so obvious to another.
Quote:
PS: I don't think "unforgiveness" is a word.
MW had it in their unabridged version. Whether or not it is a completely proper word may be the better question. Thanks.

@Thad E Ginataom
Quote:
Well, I don't care for religion --- but I like the way you are finding out about commands by playing with them . It's a great way to go.
Normally I probably wouldn't have used a religious example, but I got the idea from a statement made on TV while my aunt channel surfed. Using working examples like this is how I hard-wire things into my brain. I don't know what to say except it just works for me.
Quote:
$ cat dog
I have seen "man woman" too.

@chrism01 Thank you for the links.

You all have probably given me enough information to have a brain overload, so I will continue working and reading. Thanks again.

For the Moderators, I am going to leave this open for another day or two so that if anyone else wants to comment, they can. Then I will mark it as solved.
 
Old 01-07-2013, 10:01 PM   #9
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Arch
Posts: 3,077

Rep: Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268
Quote:
Originally Posted by Bouncerman View Post
@alieblice My current understanding of alias is that it is mostly used when you will continue repeating a task. An example might be that when you apt-get something to install it, you could create an alias that would allow you to type for example:
"sudo apt-get application" rather than "sudo apt-get install application".
Actually that wouldn't work because apt-get is an argument to sudo, so it wouldn't get expanded as an alias (see bash manual: Aliases).
Quote:
Code:
## move everything not called EVIL to EVIL directory
find . ! -name EVIL -print0 | xargs -0 mv -t EVIL
This is my absolute favorite of those because it still reflects what I want to show and does the job.
On the other hand, it would also move a file called "generosity" into EVIL.

Quote:
MW had [unforgiveness] in their unabridged version. Whether or not it is a completely proper word may be the better question. Thanks.
Hmm, google also agrees it's a word. It still sounds wrong to me, but I guess it's just a matter of getting used to it.

Quote:
For the Moderators, I am going to leave this open for another day or two so that if anyone else wants to comment, they can. Then I will mark it as solved.
FYI: people can still comment after you mark it solved. Moderators can lock the thread to prevent more replies, but they usually don't.
 
Old 01-08-2013, 04:34 AM   #10
Thad E Ginataom
Member
 
Registered: Mar 2011
Distribution: Ubuntu 12.04 with KXStudio, MATE & Compiz
Posts: 46

Rep: Reputation: 7
Quote:
Originally Posted by Bouncerman View Post
@Thad E Ginataom Normally I probably wouldn't have used a religious example, but I got the idea from a statement made on TV while my aunt channel surfed. Using working examples like this is how I hard-wire things into my brain. I don't know what to say except it just works for me. I have seen "man woman" too.
Yep. Whatever works for you is good. Also, whatever gives crystal-clear examples for others is also good.

man woman --- never, in all these years, thought of that! Creating a man page (the "an" macros make for a perfect cli argument "-man") are about as far as I ever got into the intricacies of nroff and all that stuff. If I wanted typesetting, I had a Linotype photo-typesetter that was much easier to use. Now I've forgotten it all, so I'll leave creating that man page to you
 
Old 01-08-2013, 07:59 AM   #11
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,616
Blog Entries: 26

Rep: Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988
Member Response

Hi,

Welcome to LQ!

Linux-Newbie section of SlackwareŽ-Links has several good Linux guides for a newbie.

Plus;
Quote:
Just a few links to aid you to gaining some understanding;



1 Linux Documentation Project
2 Rute Tutorial & Exposition
3 Linux Command Guide
4 Bash Beginners Guide
5 Bash Reference Manual
6 Advanced Bash-Scripting Guide
7 Linux Newbie Admin Guide
8 LinuxSelfHelp
9 Utimate Linux Newbie Guide
10 Linux Home Networking
11 Virtualization- Top 10

The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!
Quote:
"Knowledge is of two kinds. We Know a subject ourselves, or we know where we can find information upon it."- Samuel Johnson

"You must look into people as well as at them."-Chesterfield
HTH!
 
Old 01-10-2013, 03:17 PM   #12
Bouncerman
LQ Newbie
 
Registered: Jan 2013
Location: Roanoke, Virginia
Distribution: Lubuntu 12.1
Posts: 3

Original Poster
Rep: Reputation: 0
@ntubski again thank you for the info... and yes you have to watch that generosity file.

@Thad E Ginataom
Quote:
so I'll leave creating that man page to you
:$man woman
:$No manual entry for woman
Ehh... I'm single, what do I know LOL (also noticing there was no $ after woman).

@onebuck Thanks for all the added links!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Which is faster in these fread() commands? archieval Programming 27 05-14-2010 01:25 AM
how to : mount flashcard via CLI, get slackware 12.2 load faster on thinkpad X31 SiRoel Slackware 2 07-17-2009 06:06 AM
automation of CLI commands using python bharatbsharma Programming 1 03-18-2008 02:13 AM
help in linux commands in cli.. jaepi Linux - Newbie 9 04-27-2007 01:31 PM
Help on cli commands? bruno buys Linux - Software 2 08-15-2004 10:35 AM


All times are GMT -5. The time now is 11:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration