Need Assistance Understanding ls -d command in linux [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I'm trying to wrap my head around the 'ls -d' command.
I run the command 'ls -d' in any given directory and all I get is a '.'
I run the command 'ls -d */ and I get only the directories
I run the command -ls -d * and I get all files, including those that aren't directories.
The man page just states this:
list directories themselves, not their contents
Can someone please help explain how this switch is supposed to work?

The things to understand are:
ls lists the current directory, otherwise known as ., by default.
ls -d makes ls show the directory it's listing, not that contents of that directory.
The behaviors you describe all follow from that:
ls -d showing . is showing the directory you're in -- the default target of ls with no arguments given.
ls -d */ tells your shell to run ls with each directory under the current one passed as an argument; ls -d then shows the entries for each of its arguments, behaving as you report.
ls -d * tells your shell to run ls with each entry in the current directory passed as an argument. ls then lists one entry for each such argument, not showing the contents of each argument which is a directory name as it otherwise would.

Related

How to get a list of files of a huge size directory without using ls command (90GB) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
In linux server, is there a way to get the list of files in a directory
without using commands such as ls-la?
Our log directory size is too huge (almost 90GB) that
when we use ls -la command to get the list of files in that directory,
the command prompt does not come back...
echo *
... will show files in the current folder through file globbing on Bourne compatible shells.
This lists all files down one level:
echo /
In Bash, if globstar is set (set with shopt -s globstar, unset with shopt -u globstar), this will list all files recursively:
echo **
For More info, you may visit This Link
and your following problem why not you use a limit to list file?
this command may help you
ls -U | head -4
Don't know if there are other commands, but you could combine ls with other command like:
ls -la | less
which still lists your files but you can move up and down (and search) easily. less does not load all the content (your 90GB) at once but it loads lines when you move around.
Or you can save output of ls to a file to open it later
ls -la > my_files.txt

What is the operand in ls -LA do? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
As the title says what does -LA do in a ls command?
I tried reading the manual for ls and this what it said:
-A List all entries except for . and ... Always set for the super-user.
-L Follow all symbolic links to final target and list the file or directory the link references rather than the link itself. This option cancels the -P
option.
But I'm not quite sure what those mean.
the ls command prints a list of files and folders in the current directory.
When using ls -A, the command prints out ALL files and folders in the current directory. This includes hidden files and folders (like files/folders starting witch a dot). However, . (current directory) and .. (parent directory) will be ignored.
When using ls -L the command will follow symbolic links and print out the location of the reference too.
When combining this 2 options you get ls -LA which prints out a list of ALL files and folders, and also prints out the references to symbolic links in the folder.
Just try it out in the terminal. You'll see the difference.

Can't remove file $$$222.php left behind by attacker [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
My website was recently hacked and had a number of malicious files on the server. They all had the -i and -a extentions added to them
I found this out using
lsattr command and then used
chattr -ai <Filenames> to remove the immutable and append only attributes
Then rm -f <Filenames> to remove
All good
However there is one file
$$222.php which cannot be removed
When I do anything with the filename $$222.php it returns
No such filename or directory whilst trying to stat 761022.php
How can I delete this file?
This is easily duplicated.
mkdir SO
cd ./SO
echo > '$$$222.php'
ls
$$$222.php
OK we have one of these, and if you try to rm...
rm $$$222.php
rm: cannot remove ‘351522.php’: No such file or directory
We can confirm that the $$ is transformed by the shell to the process ID number.
ps
PID TTY TIME CMD
3515 pts/8 00:00:00 bash
7671 pts/8 00:00:00 ps
Turns out 3515 is just bash's process id number or PID, which occurred because the shell transforms $$ to the PID.
echo $$
3515
And it becomes 351522 not 3515222 because $2 refers to the 2nd argument to the command bash which was blank.
You can use rm -i with a wildcard to remove it, and the -i will ask you if you are sure you want to remove each matching file:
rm -i *php
rm -i *222.php
Or you can use single quotes, rm '$$$222.php'
Double quotes rm "$222.php" will still be transformed by the shell and will be transformed where it will not match.

How can I find the file which is executed when a terminal command is entered? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
Is there any way that I can find the location of the file that is run when I execute a command in the terminal? I know that commands such as ls and cd are in /bin, but is there a command that I can run on a command to see where its file is located?
You may be looking for which
Example
$ which ls
/usr/bin/ls
$ which pwd
/usr/bin/pwd
From man page
NAME
which - shows the full path of (shell) commands.
DESCRIPTION
Which takes one or more arguments. For each of its arguments it prints
to stdout the full path of the executables that would have been exe‐
cuted when this argument had been entered at the shell prompt. It does
this by searching for an executable or script in the directories listed
in the environment variable PATH using the same algorithm as bash(1).
whereis
you may also want to look at whereis
Example
$ whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1p.gz /usr/share/man/man1/ls.1.gz
NAME
whereis - locate the binary, source, and manual page files for a com‐
mand
type
type — write a description of command type
Example
$ type pwd
pwd is a shell builtin

Typed wrong mv command [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
Hi i worked on Linux server , and was running this command mv matter/*/* .
but instead i have typed this mv matter /*/* .
because of which some errors starts coming on the screen , and then i was not able to login and when we reboot the server its not coming up.
so can you please tell me what this command has done mv matter /*/* .
You can find out for yourself by inserting an echo at the beginning of the command line:
echo mv matter /*/* .
The expanded command looks like this:
mv matter /bin/ash /bin/bash /bin/echo /bin/false [...] /home/yourname [...] .
All files and directories from the top-level directories (echo /*/) have been moved to this one directory where you executed that command. It's hard to separate them from there, but you can try using a rescue CD:
move all executable files to /bin
make /sbin a symlink to /bin
move all files that look like configuration files to /etc
But since you couldn't find out for yourself what the mv command was doing exactly, you should rather ask someone who knows to fix it for you. It's a lot of work, though.

Resources