How to get the available space of $HOME as a variable in shell scripting?Ubuntu server terminal?Is bash scripting the same as shell scripting?Concatenation in Shell Scripting BashShell ScriptingShell Scripting Function questionShell scripting add slashes in file name with spaceShell scripting,Case sensitivity in shell scriptingbash shell scripting errorWhat graphical libraries are available for Bash shell scripting?
What is the command to reset a PC without deleting any files
Why are only specific transaction types accepted into the mempool?
Why CLRS example on residual networks does not follows its formula?
How old can references or sources in a thesis be?
Prevent a directory in /tmp from being deleted
Can I interfere when another PC is about to be attacked?
How to report a triplet of septets in NMR tabulation?
Download, install and reboot computer at night if needed
TGV timetables / schedules?
How much RAM could one put in a typical 80386 setup?
Are tax years 2016 & 2017 back taxes deductible for tax year 2018?
Theorems that impeded progress
How do we improve the relationship with a client software team that performs poorly and is becoming less collaborative?
A Journey Through Space and Time
Infinite past with a beginning?
Is it tax fraud for an individual to declare non-taxable revenue as taxable income? (US tax laws)
What do you call something that goes against the spirit of the law, but is legal when interpreting the law to the letter?
Can a German sentence have two subjects?
Shell script can be run only with sh command
Example of a relative pronoun
Find original functions from a composite function
Do Phineas and Ferb ever actually get busted in real time?
Is it possible to do 50 km distance without any previous training?
How does one intimidate enemies without having the capacity for violence?
How to get the available space of $HOME as a variable in shell scripting?
Ubuntu server terminal?Is bash scripting the same as shell scripting?Concatenation in Shell Scripting BashShell ScriptingShell Scripting Function questionShell scripting add slashes in file name with spaceShell scripting,Case sensitivity in shell scriptingbash shell scripting errorWhat graphical libraries are available for Bash shell scripting?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am writing a bash script to install a program for different users.
For that I want to make sure that each user has at least 500Mb available in their $HOME. My $HOME directory looks as follows
jen@ser23:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 2,9G 1,1G 1,7G 40% /
udev 10M 0 10M 0% /dev
tmpfs 13G 826M 12G 7% /run
/dev/sda3 15G 9,8G 4,1G 71% /usr
tmpfs 32G 0 32G 0% /dev/shm
tmpfs 5,0M 0 5,0M 0% /run/lock
tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/mapper/local_disk_1-tmp 3,7G 21M 3,7G 1% /tmp
/dev/mapper/local_disk_1-opt 20G 2,0G 18G 10% /opt
/dev/mapper/local_disk_1-project1 401G 287G 114G 72% /project1
/dev/mapper/local_disk_1-var 3,8G 1,7G 1,7G 50% /var
/dev/mapper/local_disk_1-project2 99G 70G 29G 71% /project2
/dev/mapper/local_disk_1-usr_local 2,0G 3,4M 1,9G 1% /usr/local
nfs4.sf0.ise.fhg.de:/g/6/TSB/Archiv 632T 349T 276T 56% /net/p/600/groupdrives/TSB/Archiv
nfs4.sf0.ise.fhg.de:/home 632T 349T 276T 56% /net/home
tmpfs 6,4G 0 6,4G 0% /run/user/12419
tmpfs 6,4G 4,0K 6,4G 1% /run/user/13471
tmpfs 6,4G 4,0K 6,4G 1% /run/user/9351
tmpfs 6,4G 0 6,4G 0% /run/user/13142
My idea is to use df -h /path/to/home | awk but I am not sure how I can get the actual available space from df -h. Any help please? Thanks, Jen.
jen@ser23:~$ df -P /net/home/j/jen
Filesystem 1024-blocks Used Available Capacity Mounted on
nfs4.sf0.dfd.fhg.de:/home 5242880 1026048 4216832 20% /net/home
command-line bash scripts
|
show 6 more comments
I am writing a bash script to install a program for different users.
For that I want to make sure that each user has at least 500Mb available in their $HOME. My $HOME directory looks as follows
jen@ser23:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 2,9G 1,1G 1,7G 40% /
udev 10M 0 10M 0% /dev
tmpfs 13G 826M 12G 7% /run
/dev/sda3 15G 9,8G 4,1G 71% /usr
tmpfs 32G 0 32G 0% /dev/shm
tmpfs 5,0M 0 5,0M 0% /run/lock
tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/mapper/local_disk_1-tmp 3,7G 21M 3,7G 1% /tmp
/dev/mapper/local_disk_1-opt 20G 2,0G 18G 10% /opt
/dev/mapper/local_disk_1-project1 401G 287G 114G 72% /project1
/dev/mapper/local_disk_1-var 3,8G 1,7G 1,7G 50% /var
/dev/mapper/local_disk_1-project2 99G 70G 29G 71% /project2
/dev/mapper/local_disk_1-usr_local 2,0G 3,4M 1,9G 1% /usr/local
nfs4.sf0.ise.fhg.de:/g/6/TSB/Archiv 632T 349T 276T 56% /net/p/600/groupdrives/TSB/Archiv
nfs4.sf0.ise.fhg.de:/home 632T 349T 276T 56% /net/home
tmpfs 6,4G 0 6,4G 0% /run/user/12419
tmpfs 6,4G 4,0K 6,4G 1% /run/user/13471
tmpfs 6,4G 4,0K 6,4G 1% /run/user/9351
tmpfs 6,4G 0 6,4G 0% /run/user/13142
My idea is to use df -h /path/to/home | awk but I am not sure how I can get the actual available space from df -h. Any help please? Thanks, Jen.
jen@ser23:~$ df -P /net/home/j/jen
Filesystem 1024-blocks Used Available Capacity Mounted on
nfs4.sf0.dfd.fhg.de:/home 5242880 1026048 4216832 20% /net/home
command-line bash scripts
1
@EODCraft Staff : Nop! :)
– Jenny
4 hours ago
1
df -P /path/to/home | awk 'NR>1 print $4'?
– Cyrus
4 hours ago
1
There's no 1,7G. There's at the moment 4216832.
– Cyrus
4 hours ago
1
Ah! I thought I should actually get the space in the partition/dev/sda1 2,9G 1,1G 1,7G 40% /
– Jenny
4 hours ago
1
If you’re on a big shared system, it’s quite possible that individual accounts have quotas, separate from the available mounted storage. For example, at my old institution, you used thediskquotacommand to check the available space. You may want to check if an equivalent system exists at your institution.
– nneonneo
1 hour ago
|
show 6 more comments
I am writing a bash script to install a program for different users.
For that I want to make sure that each user has at least 500Mb available in their $HOME. My $HOME directory looks as follows
jen@ser23:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 2,9G 1,1G 1,7G 40% /
udev 10M 0 10M 0% /dev
tmpfs 13G 826M 12G 7% /run
/dev/sda3 15G 9,8G 4,1G 71% /usr
tmpfs 32G 0 32G 0% /dev/shm
tmpfs 5,0M 0 5,0M 0% /run/lock
tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/mapper/local_disk_1-tmp 3,7G 21M 3,7G 1% /tmp
/dev/mapper/local_disk_1-opt 20G 2,0G 18G 10% /opt
/dev/mapper/local_disk_1-project1 401G 287G 114G 72% /project1
/dev/mapper/local_disk_1-var 3,8G 1,7G 1,7G 50% /var
/dev/mapper/local_disk_1-project2 99G 70G 29G 71% /project2
/dev/mapper/local_disk_1-usr_local 2,0G 3,4M 1,9G 1% /usr/local
nfs4.sf0.ise.fhg.de:/g/6/TSB/Archiv 632T 349T 276T 56% /net/p/600/groupdrives/TSB/Archiv
nfs4.sf0.ise.fhg.de:/home 632T 349T 276T 56% /net/home
tmpfs 6,4G 0 6,4G 0% /run/user/12419
tmpfs 6,4G 4,0K 6,4G 1% /run/user/13471
tmpfs 6,4G 4,0K 6,4G 1% /run/user/9351
tmpfs 6,4G 0 6,4G 0% /run/user/13142
My idea is to use df -h /path/to/home | awk but I am not sure how I can get the actual available space from df -h. Any help please? Thanks, Jen.
jen@ser23:~$ df -P /net/home/j/jen
Filesystem 1024-blocks Used Available Capacity Mounted on
nfs4.sf0.dfd.fhg.de:/home 5242880 1026048 4216832 20% /net/home
command-line bash scripts
I am writing a bash script to install a program for different users.
For that I want to make sure that each user has at least 500Mb available in their $HOME. My $HOME directory looks as follows
jen@ser23:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 2,9G 1,1G 1,7G 40% /
udev 10M 0 10M 0% /dev
tmpfs 13G 826M 12G 7% /run
/dev/sda3 15G 9,8G 4,1G 71% /usr
tmpfs 32G 0 32G 0% /dev/shm
tmpfs 5,0M 0 5,0M 0% /run/lock
tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/mapper/local_disk_1-tmp 3,7G 21M 3,7G 1% /tmp
/dev/mapper/local_disk_1-opt 20G 2,0G 18G 10% /opt
/dev/mapper/local_disk_1-project1 401G 287G 114G 72% /project1
/dev/mapper/local_disk_1-var 3,8G 1,7G 1,7G 50% /var
/dev/mapper/local_disk_1-project2 99G 70G 29G 71% /project2
/dev/mapper/local_disk_1-usr_local 2,0G 3,4M 1,9G 1% /usr/local
nfs4.sf0.ise.fhg.de:/g/6/TSB/Archiv 632T 349T 276T 56% /net/p/600/groupdrives/TSB/Archiv
nfs4.sf0.ise.fhg.de:/home 632T 349T 276T 56% /net/home
tmpfs 6,4G 0 6,4G 0% /run/user/12419
tmpfs 6,4G 4,0K 6,4G 1% /run/user/13471
tmpfs 6,4G 4,0K 6,4G 1% /run/user/9351
tmpfs 6,4G 0 6,4G 0% /run/user/13142
My idea is to use df -h /path/to/home | awk but I am not sure how I can get the actual available space from df -h. Any help please? Thanks, Jen.
jen@ser23:~$ df -P /net/home/j/jen
Filesystem 1024-blocks Used Available Capacity Mounted on
nfs4.sf0.dfd.fhg.de:/home 5242880 1026048 4216832 20% /net/home
command-line bash scripts
command-line bash scripts
edited 4 hours ago
Jenny
asked 4 hours ago
JennyJenny
968
968
1
@EODCraft Staff : Nop! :)
– Jenny
4 hours ago
1
df -P /path/to/home | awk 'NR>1 print $4'?
– Cyrus
4 hours ago
1
There's no 1,7G. There's at the moment 4216832.
– Cyrus
4 hours ago
1
Ah! I thought I should actually get the space in the partition/dev/sda1 2,9G 1,1G 1,7G 40% /
– Jenny
4 hours ago
1
If you’re on a big shared system, it’s quite possible that individual accounts have quotas, separate from the available mounted storage. For example, at my old institution, you used thediskquotacommand to check the available space. You may want to check if an equivalent system exists at your institution.
– nneonneo
1 hour ago
|
show 6 more comments
1
@EODCraft Staff : Nop! :)
– Jenny
4 hours ago
1
df -P /path/to/home | awk 'NR>1 print $4'?
– Cyrus
4 hours ago
1
There's no 1,7G. There's at the moment 4216832.
– Cyrus
4 hours ago
1
Ah! I thought I should actually get the space in the partition/dev/sda1 2,9G 1,1G 1,7G 40% /
– Jenny
4 hours ago
1
If you’re on a big shared system, it’s quite possible that individual accounts have quotas, separate from the available mounted storage. For example, at my old institution, you used thediskquotacommand to check the available space. You may want to check if an equivalent system exists at your institution.
– nneonneo
1 hour ago
1
1
@EODCraft Staff : Nop! :)
– Jenny
4 hours ago
@EODCraft Staff : Nop! :)
– Jenny
4 hours ago
1
1
df -P /path/to/home | awk 'NR>1 print $4'?– Cyrus
4 hours ago
df -P /path/to/home | awk 'NR>1 print $4'?– Cyrus
4 hours ago
1
1
There's no 1,7G. There's at the moment 4216832.
– Cyrus
4 hours ago
There's no 1,7G. There's at the moment 4216832.
– Cyrus
4 hours ago
1
1
Ah! I thought I should actually get the space in the partition
/dev/sda1 2,9G 1,1G 1,7G 40% /– Jenny
4 hours ago
Ah! I thought I should actually get the space in the partition
/dev/sda1 2,9G 1,1G 1,7G 40% /– Jenny
4 hours ago
1
1
If you’re on a big shared system, it’s quite possible that individual accounts have quotas, separate from the available mounted storage. For example, at my old institution, you used the
diskquota command to check the available space. You may want to check if an equivalent system exists at your institution.– nneonneo
1 hour ago
If you’re on a big shared system, it’s quite possible that individual accounts have quotas, separate from the available mounted storage. For example, at my old institution, you used the
diskquota command to check the available space. You may want to check if an equivalent system exists at your institution.– nneonneo
1 hour ago
|
show 6 more comments
2 Answers
2
active
oldest
votes
The important point to remember is that df operates on filesystems, which may be attached to particular folders, and if you specify a path or file, it will resolve to usage of the filesystem on which file/folder resides. So df -P /net/home/j/jen operates on the filesystem mounted at /net/home, which is nfs4.sf0.ise.fhg.de network attached server apparently.
The usage of a directory and all the files requires a recursive solution that will traverse files and directories within particular directory. The tool that you seek then, is du and in particular du -shx /net/home/user.
Keypoints (for more read man du):
duis recursive by default-sprovides summary instead of listing filesizes individually-hprovides human readable output. If you require further processing on data,-bmight be more preferable.-xis to keepdudescending into another. For instance, you could have another network server attached to/net/home/user/anotherplace, so processing that directory is undesirable as it will give incorrect filesystem usage results.
Considering that this is an assignment, further processing and manipulations on output of du are left to the reader to implement
add a comment |
It looks like you're heading towards a workable solution already in the comments, but I'm going to throw this in:
DFHOME=$( df $HOME | awk 'print $4;' | tail -n 1 )
if [ $DFHOME -lt 500000 ]; then
echo "You don't got enough space!";
fi
I'd recommend not using -h because if the size is small enough, the G will turn to an M and your solution might break.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1131935%2fhow-to-get-the-available-space-of-home-as-a-variable-in-shell-scripting%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The important point to remember is that df operates on filesystems, which may be attached to particular folders, and if you specify a path or file, it will resolve to usage of the filesystem on which file/folder resides. So df -P /net/home/j/jen operates on the filesystem mounted at /net/home, which is nfs4.sf0.ise.fhg.de network attached server apparently.
The usage of a directory and all the files requires a recursive solution that will traverse files and directories within particular directory. The tool that you seek then, is du and in particular du -shx /net/home/user.
Keypoints (for more read man du):
duis recursive by default-sprovides summary instead of listing filesizes individually-hprovides human readable output. If you require further processing on data,-bmight be more preferable.-xis to keepdudescending into another. For instance, you could have another network server attached to/net/home/user/anotherplace, so processing that directory is undesirable as it will give incorrect filesystem usage results.
Considering that this is an assignment, further processing and manipulations on output of du are left to the reader to implement
add a comment |
The important point to remember is that df operates on filesystems, which may be attached to particular folders, and if you specify a path or file, it will resolve to usage of the filesystem on which file/folder resides. So df -P /net/home/j/jen operates on the filesystem mounted at /net/home, which is nfs4.sf0.ise.fhg.de network attached server apparently.
The usage of a directory and all the files requires a recursive solution that will traverse files and directories within particular directory. The tool that you seek then, is du and in particular du -shx /net/home/user.
Keypoints (for more read man du):
duis recursive by default-sprovides summary instead of listing filesizes individually-hprovides human readable output. If you require further processing on data,-bmight be more preferable.-xis to keepdudescending into another. For instance, you could have another network server attached to/net/home/user/anotherplace, so processing that directory is undesirable as it will give incorrect filesystem usage results.
Considering that this is an assignment, further processing and manipulations on output of du are left to the reader to implement
add a comment |
The important point to remember is that df operates on filesystems, which may be attached to particular folders, and if you specify a path or file, it will resolve to usage of the filesystem on which file/folder resides. So df -P /net/home/j/jen operates on the filesystem mounted at /net/home, which is nfs4.sf0.ise.fhg.de network attached server apparently.
The usage of a directory and all the files requires a recursive solution that will traverse files and directories within particular directory. The tool that you seek then, is du and in particular du -shx /net/home/user.
Keypoints (for more read man du):
duis recursive by default-sprovides summary instead of listing filesizes individually-hprovides human readable output. If you require further processing on data,-bmight be more preferable.-xis to keepdudescending into another. For instance, you could have another network server attached to/net/home/user/anotherplace, so processing that directory is undesirable as it will give incorrect filesystem usage results.
Considering that this is an assignment, further processing and manipulations on output of du are left to the reader to implement
The important point to remember is that df operates on filesystems, which may be attached to particular folders, and if you specify a path or file, it will resolve to usage of the filesystem on which file/folder resides. So df -P /net/home/j/jen operates on the filesystem mounted at /net/home, which is nfs4.sf0.ise.fhg.de network attached server apparently.
The usage of a directory and all the files requires a recursive solution that will traverse files and directories within particular directory. The tool that you seek then, is du and in particular du -shx /net/home/user.
Keypoints (for more read man du):
duis recursive by default-sprovides summary instead of listing filesizes individually-hprovides human readable output. If you require further processing on data,-bmight be more preferable.-xis to keepdudescending into another. For instance, you could have another network server attached to/net/home/user/anotherplace, so processing that directory is undesirable as it will give incorrect filesystem usage results.
Considering that this is an assignment, further processing and manipulations on output of du are left to the reader to implement
answered 3 hours ago
Sergiy KolodyazhnyySergiy Kolodyazhnyy
75k9155327
75k9155327
add a comment |
add a comment |
It looks like you're heading towards a workable solution already in the comments, but I'm going to throw this in:
DFHOME=$( df $HOME | awk 'print $4;' | tail -n 1 )
if [ $DFHOME -lt 500000 ]; then
echo "You don't got enough space!";
fi
I'd recommend not using -h because if the size is small enough, the G will turn to an M and your solution might break.
add a comment |
It looks like you're heading towards a workable solution already in the comments, but I'm going to throw this in:
DFHOME=$( df $HOME | awk 'print $4;' | tail -n 1 )
if [ $DFHOME -lt 500000 ]; then
echo "You don't got enough space!";
fi
I'd recommend not using -h because if the size is small enough, the G will turn to an M and your solution might break.
add a comment |
It looks like you're heading towards a workable solution already in the comments, but I'm going to throw this in:
DFHOME=$( df $HOME | awk 'print $4;' | tail -n 1 )
if [ $DFHOME -lt 500000 ]; then
echo "You don't got enough space!";
fi
I'd recommend not using -h because if the size is small enough, the G will turn to an M and your solution might break.
It looks like you're heading towards a workable solution already in the comments, but I'm going to throw this in:
DFHOME=$( df $HOME | awk 'print $4;' | tail -n 1 )
if [ $DFHOME -lt 500000 ]; then
echo "You don't got enough space!";
fi
I'd recommend not using -h because if the size is small enough, the G will turn to an M and your solution might break.
edited 4 hours ago
answered 4 hours ago
KarlKarl
215
215
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1131935%2fhow-to-get-the-available-space-of-home-as-a-variable-in-shell-scripting%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
@EODCraft Staff : Nop! :)
– Jenny
4 hours ago
1
df -P /path/to/home | awk 'NR>1 print $4'?– Cyrus
4 hours ago
1
There's no 1,7G. There's at the moment 4216832.
– Cyrus
4 hours ago
1
Ah! I thought I should actually get the space in the partition
/dev/sda1 2,9G 1,1G 1,7G 40% /– Jenny
4 hours ago
1
If you’re on a big shared system, it’s quite possible that individual accounts have quotas, separate from the available mounted storage. For example, at my old institution, you used the
diskquotacommand to check the available space. You may want to check if an equivalent system exists at your institution.– nneonneo
1 hour ago