What does the -s command show? and why it changes with -h? [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
What does the the first column shows when using the -s command with ls command?
$ ls -als
41 -rw-r--r-- 1 user user 165287 Jul 10 11:18 '.tutorial.term'
1 lrwxrwxrwx 1 user user 18 Jul 1 08:40 .bash_profile -> /home/user/.bashrc
3 -rw-r--r-- 1 user user 2355 Jul 1 08:40 .bashrc
Does it show the number of blocks used for that file? or the size of blocks used for that file?
If I add the -h command to the mix, which prints sizes in a human readable format, why does the first column changes too? and why does the value differs from that in the 6th column which represents the actual size of the file?
$ ls -alsh
41K -rw-r--r-- 1 user user 163K Jul 10 12:34 '.tutorial.term'
512 lrwxrwxrwx 1 user user 18 Jul 1 08:40 .bash_profile -> /home/user/.bashrc
2.5K -rw-r--r-- 1 user user 2.3K Jul 1 08:40 .bashrc

as ls man page says, -s will print the allocated size of each file, in blocks
The size of a file and the space it occupies on your hard drive are rarely the same. Disk space is allocated in blocks. If a file is smaller than a block, an entire block is still allocated to it because the file system doesn’t have a smaller unit of real estate to use. reference
also when you use, -h option, it will change allocated block size and file content size into bytes to be human readable. So block size can be different from file size because, it often happens that file content won't use all allocated size

If you want to know why ls -l and ls -s give different sizes, read this answer. Basically, -l returns the actual size of the file while -s returns the size in the filesystem. h makes all sizes human-readable, including the ones for -s and -l.

Related

Is there a difference between commands "cp -P" and "cp -d"? [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 2 years ago.
Improve this question
man cp says:
-d same as --no-dereference --preserve=links
-P, --no-dereference never follow symbolic links in SOURCE
I test these two options and find they are same in the practice. Both just keep the symbolic links regardless of whether the symbolic(soft) link is valid or not.
Any ideas?
Thank you.
They have the same effect on symbolic links. But -d has the additional effect of preserving hard links. That is, with -d or --preserve=links, if an invocation of cp encounters multiple links to the same file, it will create multiple links to the same file in the destination. Ordinarily cp doesn't pay attention to hard links and creates files that happen to have identical contents if two source files are hard links.
$ touch foo
$ ln foo bar
$ mkdir d; cp -d foo bar d
$ mkdir P; cp -P foo bar P
$ ls -log d P
P:
total 0
-rw-rw-r-- 1 0 Apr 11 17:09 bar
-rw-rw-r-- 1 0 Apr 11 17:09 foo
d:
total 0
-rw-rw-r-- 2 0 Apr 11 17:09 bar
-rw-rw-r-- 2 0 Apr 11 17:09 foo

What is the deference between 'ls -lh' and 'ls -si'? [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 7 years ago.
Improve this question
I have executed both the comments but the size seems different in both output.
ls -lh
total 147M
-rw------- 1 root root 3.4K Sep 30 14:58 anaconda-ks.cfg
-rw-r--r-- 1 root root 247 Sep 30 14:58 install.post.log
-rw-r--r-- 1 root root 54 Sep 30 14:58 install.postnochroot.log
-rw-r--r-- 1 root root 147M Sep 30 14:58 jdk-7u79-linux-x64.gz
ls -l --si
total 154M
-rw------- 1 root root 3.5k Sep 30 14:58 anaconda-ks.cfg
-rw-r--r-- 1 root root 247 Sep 30 14:58 install.post.log
-rw-r--r-- 1 root root 54 Sep 30 14:58 install.postnochroot.log
-rw-r--r-- 1 root root 154M Sep 30 14:58 jdk-7u79-linux-x64.gz
If you would have checked the manpage for ls with the command man ls you would have seen the following:
-l use a long listing format
-h, --human-readable
with -l and/or -s, print human readable sizes (e.g., 1K 234M
2G)
-i, --inode
print the index number of each file
-s, --size
print the allocated size of each file, in blocks
So you see, each parameter just defines what and how information will be put to the screen. What you see (the difference in size) is the -h or --human-readable command, which will output more readable filesizes instead of printing always the bytes. Using -s will print the filesize in blocks on your HDD, which depends on the block size of your filesystem. From the information provided, i would say your filesystem has a 1kb blocksize. So the real content of the file would be 3.4kb, but must fill up the blocks, so on your disk the file requires 4kb or 4 blocks of space.

Linux memory issue [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 7 years ago.
Improve this question
I have a problem on my server.
When i try to start my server, it says that "there no left space on device"
If i execute the command "df", I see that on directory if full.
/dev/mapper/owegdc_vg-owegdc_logs_lv
10321208 9797004 0 100% /opt/application/owegdc/logs
When i get to the logs directory here what i see
ls -lrta
total 368
drwxr-x--- 2 oweadm grpowe 16384 Jan 15 2014 lost+found
drwxr-x--- 7 oweadm grpowe 4096 Jun 18 11:55 .
drwxr-xr-x 2 oweadm grpowe 12288 Aug 4 10:20 apache
drwxr-xr-x 2 oweadm grpowe 4096 Aug 5 00:56 batches
drwxr-xr-x 2 oweadm grpowe 4096 Sep 10 13:43 expl
drwxr-xr-x 2 oweadm grpowe 327680 Sep 10 13:50 jonas
drwxr-xr-x 11 oweadm grpowe 4096 Sep 10 13:50 ..
du -sk
9642792 .
I tried things like 'lsof' but it didn't work...
Do you have an idea ?
Thx
You could just try something like
du | sort -h -r
That would list the directories on your disk, ordered by their size descending. The first directory in the output list is the biggest one.
Better, if you're looking for large single files instead of a directory, this answer on Unix & Linux gives useful information, especially this:
find . -type f | xargs du -h | sort -rn
The output is the same, but it lists files instead of dirs.

what's the output format of 'find . -ls'? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm looking at the output of find . -ls. For example, here is a small excerpt for /lib64 on a CentOS system:
163542 28 -rwxr-xr-x 1 root root 28448 Aug 4 2010 ./libvolume_id.so.0.66.0
163423 0 lrwxrwxrwx 1 root root 16 Mar 3 2010 ./libwrap.so.0 -> libwrap.so.0.7.6
163601 0 lrwxrwxrwx 1 root root 11 Nov 9 2010 ./libc.so.6 -> libc-2.5.so
The find(1) man page says "list current file in ls -dils format on standard output". I then tried to figure it out from ls(1) man page, but I'm stumped on the second column. Any idea?
For reference: the columns (with ref. for the first line) are:
inode 163542
??? 28 what is this? stat that file doesn't mention any field equals to '28'
permissions -rwxr-xr-x
hard-links 1
owner root
group root
size(bytes) 28448
modified Aug 4 2010
name ./libvolume_id.so.0.66.0
(for logical links: -> softlink)
Doh, a casual regression against size reveals that it's roughly the number of 1024-byte blocks...

Linux: simulating/masking user ownership upon mount of 'external' partitions? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
This is my problem: I have a partition on my Ubuntu system, let's call it myhdrive, which is not automounted upon boot (so I use disk mounter applet, or Nautilus to mount it manually). When it is mounted, listing this partition looks like this in Ubuntu:
$ ls -la /media/myhdrive/
total 5743740
drwxr-xr-x 8 myusername myusername 4096 2011-07-21 08:19 .
drwxr-xr-x 4 root root 4096 2011-07-21 04:13 ..
-rw-r--r-- 1 myusername myusername 98520 2011-07-21 08:19 file1.txt
-rw-r--r-- 1 myusername myusername 3463 2011-07-21 08:19 file2.txt
Now, let's say I shutdown the Ubuntu OS - and boot, let's say, OpenSUSE from a USB key on the same machine. The myhdrive partition will again not be automounted, and then I have to mount it manually (again from the file manager there). The thing is, when mounted under OpenSUSE, the same drive displays the following listing:
$ ls -la /media/myhdrive/
total 5743740
drwxr-xr-x 8 1000 1000 4096 2011-07-21 08:19 .
drwxr-xr-x 4 0 0 4096 2011-07-21 04:13 ..
-rw-r--r-- 1 1000 1000 98520 2011-07-21 08:19 file1.txt
-rw-r--r-- 1 1000 1000 3463 2011-07-21 08:19 file2.txt
Obviously, myusername has uid of 1000 in the Ubuntu system, and there it is recognized - while the same username is not present in the OpenSUSE system, and so the uid is not replaced with a filename.
The problem is, of course, that I cannot write to the myhdrive from OpenSUSE by default - I'd first have to chown the entire partition - and then, when I get back to the Ubuntu system, I'd have to chown it back again.
It's quite clear to me that this will not be possible using the GUI tools - but is there a method or a command line switch, such that I can "fake ownership": mount this partition in such a way, that the real uid of 1000 is interpreted as 'the currently logged-in user' in the USB-booted case (including that, when writes are made to the partition by 'the currently logged-in user', they are recorded under the uid of 1000)?
Thanks in advance for any answers,
Cheers!
No. Either keep the authdb files in sync, or use an external auth server.

Resources