Effective Commands To Get Time/Size in Bash

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Effective Commands To Get Time/Size in Bash
# 8  
Old 08-13-2013
Both stat and ls commands run the system/kernel stat() call, or, more precise, the lstat() call that does not follow a symlink.
There should be two stat man pages, one for the command and one for the system/kernel call. Try
whatis stat

You see the system/kernel calls when you trace with strace (Linux, other Unix have trace/truss/tusc).
You can also see the commands run many other system/kernel calls - commands are not very efficient.
# 9  
Old 08-13-2013
stat --help

lists all the possible options that you can use to get the output you need.

For instance,
stat -c "%G" filename.txt

lists the group of the file - which you can also get from doing an
ls -ltr

, but you would have to also use

to get it done
# 10  
Old 08-13-2013
I only see that stat -c %s can be useful here
eval ` ls -lh "$LOCATION/$DATAFILE" | awk '{print "TIME=\""$6" "$7"\"", "SIZE="$5}' `

# 11  
Old 08-14-2013
Try (using bash process substitution and integer arithmetics and stat (GNU coreutils) 8.20):
read SIZE BL BLS DATE TIME REST < <(stat -c "%s %b %B %y" file)
476 8 512 2013-08-13 19:35:23.544692128
BSIZE=$(( BL * BLS ))
476 8 512 4096 2013-08-13 19:35

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Executing bash file with sudo for the second time, leads to permission denied, for some commands

I have a script that checks if the script has been ran with sudo. If the script is not ran as sudo, the current script is being executed with exec sudo bash. You are asked for a password, you type in the password, success. Everything is perfect - the commands inside the script are ran as sudo.... (1 Reply)
Discussion started by: boqsc
1 Replies

2. Shell Programming and Scripting

How to run several bash commands put in bash command line?

How to run several bash commands put in bash command line without needing and requiring a script file. Because I'm actually a windows guy and new here so for illustration is sort of : $ bash "echo ${PATH} & echo have a nice day!" will do output, for example:... (4 Replies)
Discussion started by: abdulbadii
4 Replies

3. UNIX for Beginners Questions & Answers

UNIX commands to display the biggest file by size in a directory

Hello guys, Please i need to know the biggest files in my directory let's say$ >du -h | egrep 'M|G|G' 195M ./TMP 3.6M ./TP_DEC2012 146G . But here the result it's giving me the biggest directory in the path. Actually i want to know the biggest file in 146G . Can anyone... (6 Replies)
Discussion started by: gillesi
6 Replies

4. Ubuntu

How to get columns TIME and TTY of commands ps -A?

Hi, Commands ps -A include four parameters are PID, TTY, TIME and CMD. I can not found pathnames of TTY and TIME which I can read from file in C language to get information display on screen. Thank you! Ex: PID TTY TIME CMD 1 ? 00:00:01 init (2 Replies)
Discussion started by: newbie_member
2 Replies

5. Shell Programming and Scripting

Sort by name, time, and size

How do you combine these ls commands so that I can have the outputs by name, time stamp, and size? ls -al |grep name_of_file ls -al | sort +4nr ls -l -t Please advise. (4 Replies)
Discussion started by: Daniel Gate
4 Replies

6. Shell Programming and Scripting

Execute 2 Commands at the same time

Hi @all I have got the following problem: I want my Master-Script to execute 2 Sub-scripts at the same time. How can i realize that? Thx for your help Greez Roger (2 Replies)
Discussion started by: DarkSwiss
2 Replies

7. Shell Programming and Scripting

Can BASH execute commands on a remote server when the commands are embedded in shell

I want to log into a remote server transfer over a new config and then backup the existing config, replace with the new config. I am not sure if I can do this with BASH scripting. I have set up password less login by adding my public key to authorized_keys file, it works. I am a little... (1 Reply)
Discussion started by: bash_in_my_head
1 Replies

8. Shell Programming and Scripting

Run several commands at a time

Hello guys, I am new at shell scripting and I want to create a script that runs several commands at a time, ie: uptime, w, df -h and so on and send the output of this commands to a text file so it can be send via email at a certain time using crontab. Any help will be much appreciated! (4 Replies)
Discussion started by: agasamapetilon
4 Replies

9. Shell Programming and Scripting

bash script working for small size files but not for big size files.

Hi, I have one file stat. Stat file contents are as follows: for example. H50768020040913,00260100,507680,13,0000000643,0000000643,00000,0000 H50769520040808,00260100,507695,13,0000000000,0000000000,00000,0000 H50770620040611,00260100,507706,13,0000000000,0000000000,00000,0000 Now i... (1 Reply)
Discussion started by: davidpreml
1 Replies
Login or Register to Ask a Question