ls command directory listing and file size - excel

I listed directory information using the following command ls -lrt * > testinformat.csv.
ls command to list directory information
So this is fine but I want to transform the information in folders to show summary information like below:
ls command information
I basically want to summarize the total size into one file e.g 018 folder size to the file shown as opposed to listing all the files from step 1 above. Can one do this via bash or should I use excel?I want to automate the process. Thanks
Samantha

Related

How to list down all the soft links only inside a directory in Linux systems

What is a shortcut command to list all the links inside a directory in linux machines. I can list all files and folders and copy output in a temp file and from there I can do a grep, but what I am looking for is a shortcut command to do the same.
and copy output in a temp file
This is exactly the situation for pipes!
ls -la | grep "^l"
The stdout of ls -la is redirected to the input of grep. It sounds like you know, but just for completeness the "^l" is a regular expression that searches for an l at the start of a line.
1.Open a terminal and move to that directory.
2.Type the command: ls -la. This shall long list all the files in the directory ` even if they are hidden.
3.The files that start with l are your symbolic link files.

implementing ls -lh command

I am new to linux bash , i was trying to do a problem which asks to edit bash.rc file and add an alias .The alias should be able to get the space usage of all the files and folders and display it on your screen. After digging out on internet i found that command for such thing is ls -lh but along with file or folder name and disk usage it is also showing the date at which file created and other unuseful things.enter image description here
So how can remove those things so that i only get file and folder name when i execute ls -lh command.
You have the right command, you can use tools like awk and sed to parse the output.
See this topic for example:
How to get the second column from command output?
Edit
Like Benjamin W. said in the comments, the output of ls should not be parsed.
This as been discussed on the following page: https://unix.stackexchange.com/questions/128985/why-not-parse-ls

Reason of a directory size being zero

Was doing some copy operation on a linux machine to the director /misc. and it did not perform well. After digging came to know that size of /misc is 0.
Logs:
[root#gd911-linux-host1 misc]# ls -lrt
total 0
[root#gd911-linux-host1 misc]#
But created a directory myself which empty only & checked its size, showing 4 bytes.
Logs:
[root#gd911-linux-host1 random]# du -sk
4 .
[root#gd911-linux-host1 random]#
Please let me know what is the reason of this.
Both commands are functioning 100% correctly. When you create a directory, for example:
mkdir -p misc
The directory is empty. If you use ls to list the files in the directory, it reports as expected:
$ ls -lrt misc
total 0
Because there are 0 files in the directory. Now when you look at du the disk usage taken by the directory itself, it correctly notes the size of the file (inode, links, etc.) that represents the directory on disk. Example:
$ du -sk misc
4 misc
Rest assured both are working correctly on your system. ls reporting the number of files contained within the directory, and du reporting the actual size that the directory itself takes on disk.
Stricto sensu, a directory cannot be completely empty (on Linux and POSIX systems). It is required to have the two entries for . (the directory itself) and .. (the parent directory). Use ls -als to list all entries in some directory. See ls(1) & stat(1). If using * be aware of globbing by the shell (the shell's globbing for * is skipping file names starting with ., see glob(7))
In particular opendir(3) & readdir(3) will give at least these two . & .. entries (except on failure).
Hence, a directory is always taking some place for those two mandatory entries and for additional metadata (i.e. inode).
Your /misc might have not been filled by previous cp commands perhaps for lack of permissions. Be sure that its owner is appropriate (the one used by cp commands). Check with stat /misc or with ls -ald /misc. Then chmod u+rwx /misc at least (see chmod(1); you could use as root the chown(1) command to change ownership).

Bash tab completion like ncftp?

In ncftp tab completion only shows the differences of matched files. E.g. with the following files
file123 file125 aa
then typing ls fil will first complete to ls file12 and show
3 5
Question
Can the same be done in Bash?
BASH supports tab-completion which is fairly robust. It is implemented through bash_completion. However, be aware that the way bash_completion is configured will depend on what options are set by default by your distribution. As for its basic functionality, it is exactly as you describe for ncftp. When a partial name is entered on the command line and tab is pressed, then a list of name-matched files are displayed. Once you have entered enough characters to make the name unique, tab will complete entry of the unique filename on the command line.
Linux also provides ls, but its behavior is not the same as you describe for ncftp. ls will return the names of files and directories that match the pattern you specified. By default, the name you provide to ls is not expanded. Meaning if you have file123 and file125 in a directory and issue the command ls file, you will be greeted by the error ls: cannot access bash: No such file or directory. But providing a wildcard (filename globbing) with ls file* will return both names.
If you have additional specific questions. Just leave a comment and we will do our best to help.

Generate file that contains a list of all files in a directory on linux

I know how to do this on windows, but I want to create a list of files that are in a directory on a linux machine, either as a txt or csv file. Or is there a way to save the output of a command rather than showing it on screen? Any help is appreciated.
ls lists the files in a folder, check man ls for options. To save the output of a shell command use redirection, e.g.:
ls > list.txt
or
ls -l > list.txt
etc.

Resources