# I need some help with some Linux / Unix commands, please.

**URL:** <https://boards.straightdope.com/t/i-need-some-help-with-some-linux-unix-commands-please/549219>\
**Category:** Factual Questions\
**Created:** [August 5, 2010, 2:41am UTC](https://boards.straightdope.com/t/i-need-some-help-with-some-linux-unix-commands-please/549219 "2010-08-05T02:41:09Z")\
**Posts on this page:** 12\
**Page:** 2

<div class="post-metadata">

**Author:** ![Fubaya](https://avatars.discourse-cdn.com/v4/letter/f/c2a13f/32.png) [@Fubaya](https://boards.straightdope.com/u/Fubaya)\
**Post date:** [August 7, 2010, 12:38pm UTC](https://boards.straightdope.com/t/i-need-some-help-with-some-linux-unix-commands-please/549219/21 "2010-08-07T12:38:09Z")

</div>

> [@Stoid](#):
>
> > [@Fubaya](#):
> >
> > Next time you have a file with 45,000 commands to run, you can just do this at the bash prompt.
> > 
> > ```auto
> > 
> > . filename
> > 
> > ```
> > 
> > Just a dot and the filename. Bash will “source” the file, meaning it will read the file and run all the commands in it.
> 
> …ummm…sure…whatever that means…(I had 50,000 filenames, only one command)

You copied 45,000 of these from your file and pasted them into the bash prompt:  
mv ./photos/30401?to?30500/60ccba-9919.jpg photos  
mv ./photos/30401?to?30500/60ccba-9920.jpg photos

Each one of those is a move command, so that’s 45,000 commands in all. I was just saying that if you ever have to do that again, you can have bash run the commands in the file by typing “dot filename” instead of copying and pasting to the terminal. Pasting to the terminal makes the output all funky as each line will be shown, then the output from that command.

e.g. pasting these two lines:  
echo hello  
echo world

looks like this in the terminal:

# echo hello

hello

# echo world

world

# 

The move command won’t show any output, but it will still show each time it’s pasted, so if any lines gave errors, you’d never see them. They’ll be scrolled off the screen by the rest of the pasted commands. On the other hand, doing the “dot filename” trick will give you no output unless there are errors.

I guess the odds you’ll need to do it again are pretty slim anyway.

---

<div class="post-metadata">

**Author:** ![Stoid](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/stoid/32/272_2.png) [@Stoid](https://boards.straightdope.com/u/Stoid)\
**Post date:** [August 8, 2010, 5:01am UTC](https://boards.straightdope.com/t/i-need-some-help-with-some-linux-unix-commands-please/549219/22 "2010-08-08T05:01:46Z")

</div>

Well, I managed to screw up all the permissions on my server… never tell a person who is essentially clueless how to become the root user and change things…

It’s all better now, but very disturbing overall.

Thanks for all the links.

---

<div class="post-metadata">

**Author:** ![Pasta](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@Pasta](https://boards.straightdope.com/u/Pasta)\
**Post date:** [August 8, 2010, 3:46pm UTC](https://boards.straightdope.com/t/i-need-some-help-with-some-linux-unix-commands-please/549219/23 "2010-08-08T15:46:01Z")

</div>

For information’s sake:

One of the commands up-thread that didn’t work for you involving “mv -t.” wouldn’t have worked because of a typo (that appears corrected later in the thread). It should have been “mv -t .”, where “-t” is the argument that requires a directory name to follow and “.” is that directory name. ("." is an alias that always means “current directory” and “…” means “parent directory”.

For the record, I would have done this like this:

```auto

find | grep "jpg" | xargs mv -t .

```

I generally use the more powerful “find” arguments only when I need them. “find” on its own just dumps to stdout (“standard out”) everything in and beyond the current path. The “grep” command passes only those lines of output that contain the string “jpg”, and the “xargs” command says to pass the output of _that_ to the “mv” command with the destination directory of “.”.

If the number of files is small, a more conventional “mv” command would work on its own:

```auto

mv */*.jpg .

```

If the file list is too long, though, you will see “argument list too long”. That’s exactly what the xargs/mv/-t combo is made for, as the file names become part of the stream (input/output lines) rather than being explicit arguments on the command line.

(In the “argument list too long” case, basically what the shell does when it sees “_/_.jpg” is it goes through the directories looking for matching filenames, and it then constructs the command you _could_ have typed if you typed all the names out by hand. If the resulting full command is longer than a command line can be (limited by the memory devoted to the so-called shell “environment”), it will complain.)

If you haven’t yet, I recommend embracing the “man” command. “man find”, “man mv”, etc., is a good way to learn how to use different commands. “Man pages” (as they’re called) are terse but (IMHO) in a good way. They say completely and precisely what things do, which leaves little uncertainty at the expense of perhaps a little dense-ness if there are lots of options to wade through.

---

<div class="post-metadata">

**Author:** ![Pasta](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@Pasta](https://boards.straightdope.com/u/Pasta)\
**Post date:** [August 8, 2010, 5:05pm UTC](https://boards.straightdope.com/t/i-need-some-help-with-some-linux-unix-commands-please/549219/24 "2010-08-08T17:05:59Z")

</div>

Also, everywhere in the above where I said “-t foo” I actually use “–target-directory=foo”, which is I think always available. ("-t" isn’t available in all versions of “mv”, but I seem to recall that it is sometimes, as suggested by the above posters’ suggestions to use it.)

---

<div class="post-metadata">

**Author:** ![Stoid](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/stoid/32/272_2.png) [@Stoid](https://boards.straightdope.com/u/Stoid)\
**Post date:** [August 8, 2010, 10:35pm UTC](https://boards.straightdope.com/t/i-need-some-help-with-some-linux-unix-commands-please/549219/25 "2010-08-08T22:35:42Z")

</div>

> [@Pasta](#):
>
> If you haven’t yet, I recommend embracing the “man” command. “man find”, “man mv”, etc., is a good way to learn how to use different commands. “Man pages” (as they’re called) are terse but (IMHO) in a good way. They say completely and precisely what things do, which leaves little uncertainty at the expense of perhaps a little dense-ness if there are lots of options to wade through.

Well yeah, but it assumes you have a core understanding that I don’t have…i guess the assumption is that anyone who is messing with this stuff is more of a computer geek than I am. As in:

> [@](#):
>
> CHMOD(1) BSD General Commands Manual CHMOD(1)
> 
> NAME  
> chmod – change file modes or Access Control Lists
> 
> SYNOPSIS  
> chmod [-fv] [-R [-H | -L | -P]] mode file …  
> chmod [-fv] [-R [-H | -L | -P]] [-a | +a | =a] ACE file …  
> chmod [-fhv] [-R [-H | -L | -P]] [-E] file …  
> chmod [-fhv] [-R [-H | -L | -P]] [-C] file …  
> chmod [-fhv] [-R [-H | -L | -P]] [-N] file …
> 
> DESCRIPTION  
> The chmod utility modifies the file mode bits of the listed files as  
> specified by the mode operand. It may also be used to modify the Access  
> Control Lists (ACLs) associated with the listed files.
> 
> ```
> The generic options are as follows:
> 
> -f Do not display a diagnostic message if chmod could not modify the
> mode for file.
> 
> -H If the -R option is specified, symbolic links on the command line
> are followed. (Symbolic links encountered in the tree traversal
> are not followed by default.)
> 
> -h If the file is a symbolic link, change the mode of the link
> itself rather than the file that the link points to.
> 
> -L If the -R option is specified, all symbolic links are followed.
> 
> -P If the -R option is specified, no symbolic links are followed.
> This is the default.
> 
> -R Change the modes of the file hierarchies rooted in the files
> instead of just the files themselves.
> 
> -v Cause chmod to be verbose, showing filenames as the mode is modi-
> fied. If the -v flag is specified more than once, the old and
> new modes of the file will also be printed, in both octal and
> symbolic notation.
> 
> The -H, -L and -P options are ignored unless the -R option is specified.
> In addition, these options override each other and the command's actions
> are determined by the last one specified.
> 
> Only the owner of a file or the super-user is permitted to change the
> mode of a file.
> 
> ```
> 
> DIAGNOSTICS  
> The chmod utility exits 0 on success, and \>0 if an error occurs.
> 
> MODES  
> Modes may be absolute or symbolic. An absolute mode is an octal number  
> constructed from the sum of one or more of the following values:

It’s a good thing I already knew that chmod is for file permissions, because I would never know it from the man page!

And as it is, I find it very intimidating to try and understand. I’m sure it would help enormously if I could get some basic things under my belt, such as an understanding of what

> [@](#):
>
> ```
> chmod [-fhv] [-R [-H | -L | -P]] [-E] file ...
> 
> ```

means, in terms of the syntax. How does the above translate to a REAL command? Why the double brackets? When does that apply?

I can get little tiny bits explained in isolation from other things, but then none of it comes together.

There must be some tutorial on how to understand the tutorials! Because certain things are, obviously, consistent: brackets, the minus sign, the fact that some things are capital, others lower case, the symbols… and I need to understand, because it hangs me up ALL the time, how certain symbols can be used - I know that asterisk meas “all” but when/how? In combination with what?

Since it’s very clear to you, maybe its hard for you to understand what I don’t understand, but I’m very English-oriented, so I kinda need to find a way to quite literally and quite EXACTLY translate computer syntax to English syntax. Once I’m able to do that, when I understand what each part does and the way they need to be strung together, I’m in pretty good shape. I’m good at logic puzzles and simpllified scripting - I just need to know how each “word” or symbol behaves.

Like I know that typing “ls -al” will give me a list of files in the directory I’m in and include ownership, permissions, etc… but why? What is that command actually SAYING?

ls = list? and does that always and only mean “list THIS DIRECTORY”? Or can ls be combined with other things - can you say “ls sometoherdirectoryIwilltellyouabout” perhaps by “ls /other/directory/someplace/else”?

---

<div class="post-metadata">

**Author:** ![septimus](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/septimus/32/410_2.png) [@septimus](https://boards.straightdope.com/u/septimus)\
**Post date:** [August 9, 2010, 4:07am UTC](https://boards.straightdope.com/t/i-need-some-help-with-some-linux-unix-commands-please/549219/26 "2010-08-09T04:07:02Z")

</div>

> [@Stoid](#):
>
> So, rather than continue to wrestle, I did what made sense to me.

I think it’s wonderful you found a simple way to do this by yourself. Yours is the way I do it, though use of wildcard (‘\*’) may simplify things. The one problem that may arise is different files in different subdirectories that share a name and you don’t want to overwrite (and destroy) the other. (In my case, this worries me so much I have a defined alias ‘dupsindir’ just to check for such duplicates.)

I didn’t check the solutions posted using ‘find’, ‘|’ etc. Overkill.

My machine lacks a Linux driver for my digital camera so I transfer them with the Windows driver, end up with ridiculously long names and paths, reboot into Linux just to do ‘mv’ similar to yours.

---

<div class="post-metadata">

**Author:** ![si\_blakely](https://avatars.discourse-cdn.com/v4/letter/s/d9b06d/32.png) [@si\_blakely](https://boards.straightdope.com/u/si_blakely)\
**Post date:** [August 9, 2010, 8:55am UTC](https://boards.straightdope.com/t/i-need-some-help-with-some-linux-unix-commands-please/549219/27 "2010-08-09T08:55:52Z")

</div>

> [@Stoid](#):
>
> …
> 
> > [@](#):
> >
> > ```
> > chmod [-fhv] [-R [-H | -L | -P]] [-E] file ...
> > 
> > ```
> 
> means, in terms of the syntax. How does the above translate to a REAL command? Why the double brackets? When does that apply?

chmod has modifiers: **-f** , **-h** and **-v** can be combined and apply in all circumstances. **-R** is also a modifier (descend subdirectories), and has it’s own three modifiers ( **-H** , **-L** , **-P** ), only one of which can apply (thus the bar seperator **|** meaning _OR_). -E, -C, -N are additional modifiers.

To be fair, I don’t know what system you are working on, my Centos system has a much clearer man page for _chmod_, and my _chmod_ allows option combining, so all the primary options can be combined (_chmod -fR_ …) works.

> [@Stoid](#):
>
> I can get little tiny bits explained in isolation from other things, but then none of it comes together.
> 
> There must be some tutorial on how to understand the tutorials! Because certain things are, obviously, consistent: brackets, the minus sign, the fact that some things are capital, others lower case, the symbols… and I need to understand, because it hangs me up ALL the time, how certain symbols can be used - I know that asterisk meas “all” but when/how? In combination with what?

Any place a command expects a file/directory name, you can use a file expansion modifier like \*\*\*\*\* or **?** (any single character). [Unix Wildcards](http://www.robelle.com/smugbook/wildcard.html)

> [@Stoid](#):
>
> Like I know that typing “ls -al” will give me a list of files in the directory I’m in and include ownership, permissions, etc… but why? What is that command actually SAYING?

list a directory (if no directory specified, use the current directory, an implied **.** ) with the -l (long listing) and -a (include hidden files starting with a **.** )

> [@Stoid](#):
>
> ls = list? and does that always and only mean “list THIS DIRECTORY”? Or can ls be combined with other things - can you say “ls sometoherdirectoryIwilltellyouabout” perhaps by “ls /other/directory/someplace/else”?

Yes, you can list a specified directory.

Si

---

<div class="post-metadata">

**Author:** ![Fubaya](https://avatars.discourse-cdn.com/v4/letter/f/c2a13f/32.png) [@Fubaya](https://boards.straightdope.com/u/Fubaya)\
**Post date:** [August 11, 2010, 3:29pm UTC](https://boards.straightdope.com/t/i-need-some-help-with-some-linux-unix-commands-please/549219/28 "2010-08-11T15:29:17Z")

</div>

If you want to know what certain options to a command do, try typing “command --help” in a terminal. For example, here is the output of “ls --help” for the particular version of ls that I have on my phone:

\*# ls --help  
BusyBox v1.16.1androidBTEP (2010-05-05 21:05:13 PDT) multi-call binary.

Usage: ls [-1AacCdeFilnpLRrSsTtuvwxXhk] [FILE]…

List directory contents

Options:  
-1 List in a single column  
-A Don’t list . and …  
-a Don’t hide entries starting with .  
-C List by columns  
-c With -l: sort by ctime  
–color[={always,never,auto}] Control coloring  
-d List directory entries instead of contents  
-e List full date and time  
-F Append indicator (one of \*/=@|) to entries  
-i List inode numbers  
-l Long listing format  
-n List numeric UIDs and GIDs instead of names  
-p Append indicator (one of /=@|) to entries  
-L List entries pointed to by symlinks  
-R Recurse  
-r Sort in reverse order  
-S Sort by file size  
-s List the size of each file, in blocks  
-T N Assume tabstop every N columns  
-t With -l: sort by modification time  
-u With -l: sort by access time  
-v Sort by version  
-w N Assume the terminal is N columns wide  
-x List by lines  
-X Sort by extension  
-h List sizes in human readable format (1K 243M 2G)

# 

-

---

<div class="post-metadata">

**Author:** ![BigT](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/bigt/32/12044_2.png) [@BigT](https://boards.straightdope.com/u/BigT)\
**Post date:** [August 12, 2010, 3:07am UTC](https://boards.straightdope.com/t/i-need-some-help-with-some-linux-unix-commands-please/549219/29 "2010-08-12T03:07:35Z")

</div>

I’d be more likely to stick “man” in front of it. Commands that come with the system are all going to have manual pages.

---

<div class="post-metadata">

**Author:** ![Fubaya](https://avatars.discourse-cdn.com/v4/letter/f/c2a13f/32.png) [@Fubaya](https://boards.straightdope.com/u/Fubaya)\
**Post date:** [August 12, 2010, 4:56am UTC](https://boards.straightdope.com/t/i-need-some-help-with-some-linux-unix-commands-please/549219/30 "2010-08-12T04:56:18Z")

</div>

> [@BigT](#):
>
> I’d be more likely to stick “man” in front of it. Commands that come with the system are all going to have manual pages.

I was just showing another option. --help is usually a concise list of the different options while man pages can get into some pretty deep territory, even history at times. The man page for rsync is 3342 lines long, for example and no newbie is going to look at that to find out how to do a dry run or something.

---

<div class="post-metadata">

**Author:** ![Bytegeist](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@Bytegeist](https://boards.straightdope.com/u/Bytegeist)\
**Post date:** [August 12, 2010, 3:11pm UTC](https://boards.straightdope.com/t/i-need-some-help-with-some-linux-unix-commands-please/549219/31 "2010-08-12T15:11:18Z")

</div>

> [@Pasta](#):
>
> Also, everywhere in the above where I said “-t foo” I actually use “–target-directory=foo”, which is I think always available. (“-t” isn’t available in all versions of “mv”, but I seem to recall that it is sometimes, as suggested by the above posters’ suggestions to use it.)

That option is probably a GNU extension. Neither form of it exists in the MacOS X or Solaris versions of the “mv” command. Also, it’s not mentioned in the POSIX documentation for “mv”.

---

<div class="post-metadata">

**Author:** ![Digital\_Stimulus](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@Digital\_Stimulus](https://boards.straightdope.com/u/Digital_Stimulus)\
**Post date:** [August 15, 2010, 10:57pm UTC](https://boards.straightdope.com/t/i-need-some-help-with-some-linux-unix-commands-please/549219/32 "2010-08-15T22:57:17Z")

</div>

I didn’t really want to resurrect this thread, but I just stumbled upon the following and it’s worth it: [How To Look Like A UNIX Guru](http://www.cs.usfca.edu/~parrt/course/601/lectures/unix.util.html).

Chock full o’ UNIX-y goodness, that page is.

[Previous page](https://boards.straightdope.com/t/i-need-some-help-with-some-linux-unix-commands-please/549219.md?page=1)
