FAQ: Manipulation - ls & Combining Options

This community-built FAQ covers the “ls & Combining Options” exercise from the lesson “Manipulation”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Learn the Command Line

FAQs on the exercise ls & Combining Options

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in Language Help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

I just have a couple basic questions about the ls -l output and the ls -a output:

  1. Certain files have a “dr” prefix before their wrx permissions. What does the “dr” indicate?
  2. When showing hidden files, we see two files called simply “.” and “…” respectively. What are those?

Thanks!

(EDIT: when trying to just type two dots, the output on this comment becomes an ellipsis automatically… that second file should only be two dots, not three!)

1 Like

the first character is always a d or a -. this lets you know whether or not that particular entry for your results of ls -l is a directory (it will show d) or a file (-).

The r stands for the owners permission to read the file/directory.

More about file permissions here

Hi !

In my git bash terminal when typing - (test is a file in the desktop directory which is my present working directory.

chmod a-x test

nothing happens. i.e. when I type ls -l again - the permissions are still the same i.e drwxr-xr-x.

Also, there is only one user of this laptop and the files are also showing only one username. So, could it be because of that - it doesnt make sense though - if I am permitted to change the permissions of all users, then if there is only one user also, it should permit me to change the permissions of that user.

If anyone can clarify, would be appreciated. Thanks.

‘Test’ is a folder - not a file - sorry.

You mention gitbash so I guess you’re on windows? Unfortunately the normal windows filesystems don’t properly support unix permissions so commands like chmod won’t alter anything. You can have a wee web search for more details if you’re curious about it.

I get it. Thank you for the help.

1 Like

I don’t understand what hidden files are. You can’t see them normally, but why? Is there something special done to them to make them that way?

1 Like

This differs on your OS but in most if not all UNIX based systems “dotfiles” are considered hidden files. These are quite simply files where the first character of the filename is a . dot/fullstop character, e.g .filename. There’s nothing special about the file itself (no metadata or otherwise).

An example of ls -lA; list (A)lmost-all directory contents in (l)ist format showing some dotfiles:

drwxr-xr-x 8 user user 4096 Jun 11 19:20 .git
-rw-r--r-- 1 user user  785 Jun 10 13:07 .gitattributes
-rw-r--r-- 1 user user  131 Jun 10 13:07 .gitignore

A number of shell based commands ignore dotfiles by default (which extends to most file viewers as well). But this is more a matter of convention that anything special about the file, I could simply rename a random text file to include a . as the first character and it is now a “hidden file”.

So not being able to “see” them normally is just a tool for convenience; the majority of the time you don’t want to see or interact with them.

I have a few questions for hidden files that can be showcased through ls -a or ls -alt,

What is the use of those hidden files?
Should we modify them?
How do we create them? If their creation is automatic, what causes their creation?

As per my previous reply hidden is a little bit of a misnomer, they are only “hidden” in the sense that certain commands are not designed to show/interact with them. You could make any new file or directory “hidden” by simply adding a dot . to the start of the name.

For example to create a new “hidden” file-
touch .newfile
Or to create a new “hidden” directory-
mkdir .empty

Such dotfiles are commonly used for configuration or to hide folders we simply don’t want to see every time we use commands like ls (for example .cache and .config directories).

In some cases we want to modify such dotfiles as it how we configure many things on unix systems. The course covers alteration of .bashrc for example which helps initialise your interactive shell.

Like most files you probably don’t want to go around deleting them until you know what they do and you’re sure it is safe to do so. Chances are they’re there for a good reason.

Running certain programs might automatically create some dotfiles, e.g. .bash_history (many programs output things like configs, error logs, caches and history for example). This is no different to most software on Windows or otherwise (the first time run normally creates loads of files and subsequent runs updates things). You just might be able to find some of them a little easier on a *nix based system.

hello Sir ,
I have a Doubt when ls -l is used then i am getting the following output

drwxr-xr-x 4 ccuser ccuser 172 May 26 2021 action
drwxr-xr-x 4 ccuser ccuser 77 May 26 2021 comedy
drwxr-xr-x 4 ccuser ccuser 38 Jul 8 2015 drama
-rw-r–r-- 1 ccuser ccuser 0 May 26 2021 genres.txt

here i have following doubts

  1. column 6 which tells about "The date & time that the file was last modified " is showing only the date and not time.
  2. column 4 which shows "The name of the group that owns the file. Here the group name is eng " is actually showing only ccuser
  3. column 3 which shows “The username of the file’s owner. Here the username is cc .” is actually showing ccuser again
  4. column 2 which shows " Number of hard links. This number counts the number of child directories and files. This number includes the parent directory link ( .. ) and current directory link ( . ). " is showing wrong information as below :-

a) under drama it should be showing 10 but is showing only 4
b) under comedy it should be showing 6 but showing only 4
c) under action it should be showing 8 but showing only 4

1 Like
  1. It may vary depending on the version of ls but you might need to use the --time-style command (see the manual page for info) or ls -l --full-time might suit your needs.

  2. I think they’re ony referring to eng in their example. In your case the group is ccuser.

  3. Same thing.

  4. I think that statement about the number provided is not correct in many cases (it is actually OS dependent)-

This number counts the number of child directories and files.

For most Linux systems I’m familiar with you get a count of the number of subdirectories in that directory (only at that level, it is not recursive) and not the file count at all. If I’m not mistaken the rules for OSX and possibly some other systems are different and it will count files too. This is an unfortunate fact of life around unix based systems that they’ve branched out and may follow ever so slightly different rules.

For the count of 4 in drama for example you have the . and .. directory links along with the biopic and historical directories making a total of 4. It does not count files and it does not count the contents of subdirectories.

1 Like

thanks a lot sir for the prompt reply sir

1 Like

I’m going through this tutorial. Does this picture actually follow along with the assignment?

When I types in ls -alt it printed out the following:
drwxr-xr-x 5 ccuser ccuser 85 Jan 5 03:18 …
drwxr-xr-x 4 ccuser ccuser 77 May 26 2021 .
-rw-r–r-- 1 ccuser ccuser 0 May 26 2021 .gitignore
drwxr-xr-x 2 ccuser ccuser 28 May 26 2021 satire
drwxr-xr-x 2 ccuser ccuser 47 May 26 2021 slapstick
-rw-r–r-- 1 ccuser ccuser 14 May 26 2021 the-office.txt

I know … and . shouldn’t show up because they’re hiding (I’m assuming .gitignore is also similar), but in the image, there’s no the-office.txt in the comedy section, which should be visible.

I’m also trying to figure out the hard links and in the explanation, it includes the following:
$ ls -l
drwxr-xr-x 5 cc eng 4096 Jun 24 16:51 action
drwxr-xr-x 4 cc eng 4096 Jun 24 16:51 comedy
drwxr-xr-x 6 cc eng 4096 Jun 24 16:51 drama
-rw-r–r-- 1 cc eng 0 Jun 24 16:51 genres.txt

I for the life of me can’t figure out why drama is 6. I’m also not entirely sure what hard links are. Are those the directories and files within the working directory?

It seems like the lesson may have been updated or changed since that figure was devised so, no it seems like the-office.txt should be included in that figure. Not ideal but not the end of the world either.

As for links counts Part 4 of my previous reply- FAQ: Manipulation - ls & Combining Options - #13 by tgrtim might be useful, the count they describe isn’t actually always used in unix, differing OS systems may use different counts (for example my current system does not include files in the count).

Regarding using ls -l for link counts… I honestly like working in the shell, I almost never use GUI file explorers and I can honestly say I’ve made use of the link count with ls -l maybe once or twice. It’s really not that important for day to day work and even if you are a user who makes use of hard links you’re still unlikely to run around trying to count them with ls. If you really want to know about hard links a web search will net you some decent tutorials (too much to cover in a reply).

Long story short, don’t lose too much sleep over that particular number in ls -l . It’s really not that useful at the end of the day.

here th answer i want write out the full print for ls -alt but i will give tyou the command

$ ls -alt
total 0




$ cd comedy/
$ ls
satire slapstick the office.txt
$ pwd
home/ccuser/workspace/movie/comedy
$ ls -alt
total 4





$

this code shall pass you do not use (-----------) i used that as a placeholder from the file content
but focus more on the commands prompt $ and this shall pass ypu

$ ls -alt
total 0
drwxr-xr-x 5 ccuser ccuser  85 Dec 22 09:26 .
drwxrwxr-x 1 ccuser ccuser  20 Dec 22 09:26 ..
drwxr-xr-x 4 ccuser ccuser 172 Dec 19 17:09 action
drwxr-xr-x 4 ccuser ccuser  77 Nov 28 17:53 comedy
-rw------- 1 ccuser ccuser   0 Apr 25  2022 genres.txt
-rw------- 1 ccuser ccuser   0 Apr 25  2022 .preferences
drwxr-xr-x 4 ccuser ccuser  38 Jul  8  2015 drama

I would like to have more info about the acces right (first column).
In this case “drwxr-xr-x” “d” indicate a directory, but why do we have two “r” in “rwxr” as acces right for owner?
Same question for line 4 “drwxrwxr-x”. Looks like this is a directory with “rwxrwxr” rights for owner, “x” right for group and no rights for user.
On line 7 and 8 we have a file (because it starts with -) with “rw” rights for owner and no rights for others?
Please help :face_with_peeking_eye:

in a situation like that you might have to switch over to $ suso ill research a clean way to explained to you .

What that means?

I was looking over internet for an answer to my question but couldn’t find one.