Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learn Linux Quickly

You're reading from   Learn Linux Quickly A beginner-friendly guide to getting up and running with the world's most powerful operating system

Arrow left icon
Product type Paperback
Published in Aug 2020
Publisher Packt
ISBN-13 9781800566002
Length 338 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Ahmed AlKabary Ahmed AlKabary
Author Profile Icon Ahmed AlKabary
Ahmed AlKabary
Arrow right icon
View More author details
Toc

Table of Contents (24) Chapters Close

Preface 1. Your First Keystrokes 2. Climbing the Tree FREE CHAPTER 3. Meet the Editors 4. Copying, Moving, and Deleting Files 5. Read Your Manuals! 6. Hard versus Soft Links 7. Who Is Root? 8. Controlling the Population 9. Piping and I/O Redirection 10. Analyzing and Manipulating Files 11. Let's Play Find and Seek 12. You Got a Package 13. Kill the Process 14. The Power of Sudo 15. What's Wrong with the Network? 16. Bash Scripting Is Fun 17. You Need a Cron Job 18. Archiving and Compressing Files 19. Create Your Own Commands 20. Everyone Needs Disk Space 21. echo "Goodbye My Friend" 22. Assessments 23. Other Books You May Enjoy

Passing command arguments

So far, we ran the ls command only on the current working directory. However, you can list the contents of any directory without having to change to it. For example, if your current working directory is /home/elliot:

elliot@ubuntu-linux:~$ pwd
/home/elliot

You can list all the files in /home/angela by running the ls -a /home/angela command:

elliot@ubuntu-linux:~$ ls -a /home/angela
. .. .bash_history .bash_logout .bashrc Music .profile
elliot@ubuntu-linux:~$ pwd

/home/elliot
elliot@ubuntu

I was able to list the contents of /home/angela while still being in /home/elliot. This is possible because the ls command accepts any file as an argument.

WHAT IS AN ARGUMENT?

An argument, also called a command-line argument, is simply any filename or data that is provided to a command as an input.
Figure 11: Linux Command Structure

You can see in the preceding image the general structure of a Linux command.

In Linux terminology, we use the verb pass when talking about command options and arguments. To use the correct Linux terminology, for example, in the preceding image, we say, "We passed the /home/angela directory as an argument to the ls command."

You will often find Linux users very keen on using the right terminology. Moreover, using the proper terminology can help you pass a job interview and land your dream job!

Notice in the preceding figure, we used the plural nouns options and arguments. That's because some commands can accept multiple options and arguments.

For example, we can do a long listing for all the files in /home/angela by running the ls -a -l /home/angela command:

elliot@ubuntu-linux:~$ ls -a -l /home/angela 
total 28
drwxr-xr-x 3 angela angela 4096 Jan 20 13:43 .
drwxr-xr-x 9 root root 4096 Jan 17 04:37 ..
-rw------- 1 angela angela 90 Jan 20 13:43 .bash_history
-rw-r--r-- 1 angela angela 220 Apr 4 2018 .bash_logout
-rw-r--r-- 1 angela angela 3771 Apr 4 2018 .bashrc
drwxrwxr-x 2 angela angela 4096 Jan 19 19:42 Music
-rw-r--r-- 1 angela angela 807 Apr 4 2018 .profile

So now you see a long listing of all the files in /home/angela including the hidden files, also notice that the ordering of the options doesn't matter here, so if you run the ls -l -a /home/angela command:

elliot@ubuntu-linux:~$ ls -l -a /home/angela 
total 28
drwxr-xr-x 3 angela angela 4096 Jan 20 13:43 .
drwxr-xr-x 9 root root 4096 Jan 17 04:37 ..
-rw------- 1 angela angela 90 Jan 20 13:43 .bash_history
-rw-r--r-- 1 angela angela 220 Apr 4 2018 .bash_logout
-rw-r--r-- 1 angela angela 3771 Apr 4 2018 .bashrc
drwxrwxr-x 2 angela angela 4096 Jan 19 19:42 Music
-rw-r--r-- 1 angela angela 807 Apr 4 2018 .profile

You will get the same result. This was an example of passing two commands options, what about passing two arguments? Well, you can do a long listing for all the files in /home/angela and /home/elliot at the same time by passing /home/elliot as a second argument:

elliot@ubuntu-linux:~$ ls -l -a /home/angela /home/elliot
/home/angela:

total 28
drwxr-xr-x 3 angela angela 4096 Jan 20 13:43 .
drwxr-xr-x 9 root root 4096 Jan 17 04:37 ..
-rw------- 1 angela angela 90 Jan 20 13:43 .bash_history
-rw-r--r-- 1 angela angela 220 Apr 4 2018 .bash_logout
-rw-r--r-- 1 angela angela 3771 Apr 4 2018 .bashrc
drwxrwxr-x 2 angela angela 4096 Jan 19 19:42 Music
-rw-r--r-- 1 angela angela 807 Apr 4 2018 .profile

/home/elliot:
total 28
drwxr-xr-x 3 elliot elliot 4096 Jan 20 16:26 .
drwxr-xr-x 9 root root 4096 Jan 17 04:37 ..
-rw------- 1 elliot elliot 90 Jan 20 13:43 .bash_history
-rw-r--r-- 1 elliot elliot 220 Dec 26 23:47 .bash_logout
-rw-r--r-- 1 elliot elliot 3771 Dec 26 23:47 .bashrc
drwxr-xr-x 2 elliot elliot 4096 Jan 19 14:20 Desktop
-rw-r--r-- 1 elliot elliot 807 Apr 4 2018 .profile

So now, you can see the contents of both the /home/elliot and /home/angela directories at the same time.

You have been reading a chapter from
Learn Linux Quickly
Published in: Aug 2020
Publisher: Packt
ISBN-13: 9781800566002
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image