date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,431,696,284,000
how do I set it so clear command clears the output that was stored in ram from my understanding, konsole keeps screen output in ram. I want to clear that when I clear the visible part of the screen with the clear command.
Clearing the ram used by whatever running process is a facility rarely offered to the user. More over, unless you precisely know the code the process is running, it is just impossible to know what is being stored where. The visible part of the screen as well as some variable amount of lines that were previously displ...
have clear screen clear konsole ram
1,431,696,284,000
I am working on ARM-based processor (OS version: Linux 3.4.35) and I need to analyze the processor's performance while some processes are running, by typing top command, I can see some statistics but I do not understand the details there, what information should I look for ? Here the details I need to understand (diff...
The best place to get started with learning about a given Linux/Bash command is to reference the manual page or manpage of the given command. Here is a link to a top manpage. In shell, you should be able to read the manpage by simply executing man top. I will also include a link to a blog explaining top. The relevant...
How to analyze top command results: CPU & RAM consumption
1,431,696,284,000
I have just upgraded my PC with another 32GB of RAM. Both BIOS and lshw does acknowledge the existence of all four 16GB RAM modules, but neither free, top and htop sees the actual memory. $ sudo lshw adam-potwor width: 64 bits capabilities: smbios-3.0 dmi-3.0 smp vsyscall32 configuration:...
The problem was caused by improper memory slot configuration. After replacing the memory into A2, B2, C2 and D2 slots, just as Mark Patrick described, solved all the problems. So the morale of the story is: when Linux (or Windows) does not use all the installed memory (even if it sees the chips in the slots), check i...
Ubuntu 18.04 does not use more than 32GB of RAM [closed]
1,431,696,284,000
How to setup limit for process to memory usage? Similar to open files limit in /etc/security/limits.conf: ubuntu soft nofile 4096 ubuntu hard nofile 8192 E.g. while I'm launching python script with raw eval of json data from 1.1G file, python takes whole of RAM, while crea...
Using the same file limits.conf you can limit: data - max data size (KB) memlock - max locked-in-memory address space (KB) rss - max resident set size (KB) as - address space limit (KB) stack - max stack size (KB) So it's pretty much you can do. After setting up limits you can check this level with ulimit -a → you c...
Memory Usage in Linux [duplicate]
1,431,696,284,000
I've never seen or heard anything like this before, and I can't find anything else online that is at all similar. I've upgraded my network to gigabit and have been transferring large files lately (this one in question is a bunch of DVD images totaling over 200GB). Whenever I try to copy a set of files a few gigs and l...
Marco's comment inspired me to try a few things that I didn't think of, and I discovered the answer. Well, I guess I discovered an alternative. If anyone knows more about this, please add an answer. I ought to have specified beforehand how I was transferring the file. This was done over the network (of course) via a W...
Linux Mint Stops Network File Transfers to Load Data into RAM
1,431,696,284,000
I try Peppermint OS (a distro based on Lubuntu) on live usb. I check ram by the command free -h and the result is peppermint@peppermint ~ $ free -h total used free shared buff/cache available Mem: 3.8G 1.0G 1.0G 866M 1.8G 1.8G Swap: ...
So it has detected your 4GB (decimal) swap partition, and automatically enabled it. I think this is fairly common. It is probably from common Ubuntu code. It is also using 2 x 1GB of zram swap. Data swapped to zram is compressed, and stored in RAM. This can be particularly useful on low-memory systems. Android c...
Why is swap so large when I try Peppermint OS on live usb? (The usb's size is smaller than the swap's size)
1,532,520,757,000
I have attempted to make Tiny Core Linux, Archboot (didn't get very far), and SliTaz remastered live CD's with lsdvd included, in order to create a lightweight transcoding solution that allows as much of the processing to be on the transcoding as I can manage. Additionally, I opted for these RAM distributions so that...
It turned out to be an issue with VirtualBox's "Passthrough" feature for the Host IDE Disc Drive. Without it, lsdvd cannot fully function.
Can't Get "lsdvd" To Work On Remastered Live CD's
1,532,520,757,000
After working for more than a day on my machine, swap becomes about 1GB. Some of my panel plugins go to swap so they become laggy. Moreover, the system doesn't unswap until I make it to do it swapoff -all;swapon --all. Are there mechanisms in the Linux kernel to unswap when the load is low or something like this? Som...
When Linux needs to find RAM to store something, it looks for the pages in RAM that have been unused for the longest time. If these pages belong to files, they're freed. If these pages are process memory, they're moved to swap. Linux doesn't know what pages are going to be used soon, and doesn't know what pages are go...
Is there way to force Linux to unswap when there is low CPU usage?
1,532,520,757,000
we have Linux machine that used the disk /dev/sdb to save data , we configured the mount point in /etc/fstab disk is 100G , and mount point is the folder /data now we want to use the memory ( we have 256G ) , instead of the disk so is it possible to use the memory RAM 256G instead to mount the disk? if yes how to mou...
More or less like you would for /dev/sdb1. First of all unmount /dev/sdb1 (you can mount it somewhere else). umount /dev/sdb1 You can create another directory and mount the disk there: mkdir /physical-data mount /dev/sdb1 /physical-data ...(the other options you already have). In /etc/fstab, rename "/data" to "/phys...
RAM disk + is it possible to mount to RAM instead of disk
1,532,520,757,000
I use GNU make to start benchmarks of different write/read calls in R. In some cases this will result in my RAM being fully used and the process being killed (which is fine, since I want to see the limits). The issue however is, that the whole make process is killed and not only the specific script-call. For example, ...
This happens because Make stops execution by default if any command indicates that it failed. You can disable this by prefixing commands with -: small.csv: tester.R -Rscript tester.R --size small large.csv: tester.R -Rscript tester.R --size large Alternatively, you can run make with the -k option to ...
Make: start process that if being killed, does not kill make
1,532,520,757,000
I've been having an issue for many years where I have vm.swappiness=1 in sysctl.conf, but even though there's plenty of RAM available (possibly almost full in terms of cached, although still 4GB free usually, but "available" is still quite free), swap keeps getting used all the time and sometimes almost full. I simply...
The only way to fully disable swap is to not set it up in the first place. Setting vm.swappiness to 0 will cause the kernel to only use swap as a last resort; it is currently documented as At 0, the kernel will not initiate swap until the amount of free and file-backed pages is less than the high watermark in a zone....
On AlmaLinux 8 or CentOS 7, does vm.swappiness=0 mean that Swap is fully disabled?
1,532,520,757,000
without overcommitment, every fork() would require enough free storage to duplicate the address space, even though the vast majority of pages never undergo copy-on-writes. The above statement is taken from Robert Love's book (Linux System Programming 2nd edition, Memory management chapter, Overcommitting and OOM...
You can overcommit without swap. The word "storage" in Robert Love's book in this context refers to physical RAM. The kernel sets up a memory space for the process that does not yet contain mappings to physical RAM, or points to shared page frames, in the case of Copy-on-Write. The mappings are created on demand, when...
Will copy-on-write in main memory work while swap is off?
1,532,520,757,000
I'm using the function rosbag of ROS. rosbag can record lots of data from other ROS nodes. In a word, it will generate a huge file, such as a file of 200MB. After generating such a file, I found that the buff/cache of the system increases a lot. Here is my capture: Before rosbag: After rosbag: You can see that after...
In free’s output: “free” represents memory which is unused; “buff/cache” represents memory used by buffers (data in memory which is waiting to be written to disk) and cache (data on disk which is also available in memory); “available” represents the amount of memory a process can allocate and use without hitting swap...
free -m: free size reduced because of cache/buff
1,532,520,757,000
I feel that with all the additional apps pre-installed, and relying heavily on deriving elements from Ubuntu and Gnome, elementary must be heavy. So I would like to know an as-quantitative-as-possible analysis of how heavy the OS is on RAM (and may be the system in overall) compared to Classic-Ubuntu/Gnome-Ubuntu. Th...
What applications are preinstalled is completely irrelevant. An application that is installed but not running costs nothing but disk space. I don't know why you feel that elementary must be heavier than Gnome. Gnome itself is pretty heavy. There was an article comparing Linux desktop environments in the Layer 3 Networ...
How heavy is elementaryOS over classic Ubuntu? [closed]
1,532,520,757,000
I have some old PCs runnning on my business. And by old I mean PENTIUM-3 800 MHZ and AMD DURON 950 MHZ, with 256MB RAM. They are running my business software today on Windows XP. I want to run Linux on them. But today's Linuxes versions require at least 512MB on RAM. Side note: I know that SWAP and RAM have HUGE speed...
You can use lightweight distributions that require less ram. Linux doesn't need 512MB. SWAP is kind of temporary substitution for RAM. You could use it, but it's much slower than RAM, and could make your experience unpleasant. Still, you can check out Puppy Linux requirements. It's known for being lightweight. Also, h...
How low can I go on RAM?
1,532,520,757,000
I recently installed a copy of Ubuntu Server 14.04.2 LTS on a cluster. All appears to be working fine, but a large portion (around half) of our total available RAM is being used. I.e., when I run free I get the following output (the buffers/cache line being the relevant one): total used free ...
I figured out that a large portion of the memory usage was, in fact, attributable to inactive memory used by exited processes. The most accurate way to determine how much memory is available post-January 2014 is to look at MemAvailable in /proc/meminfo. You can also see the amount of inactive memory is this file.
Substantial portion of memory used is not accounted for by user processes
1,532,520,757,000
Someone told me that there is a sub folder off of dev that basically allows you to tell the OS to keep the contents of that folder cached in RAM. So if I put some files & directories in /dev/somefolder the OS would keep this folder's content cached. What folder is that? I'm on ubuntu 12.04, in case that matters.
There is /dev/shm, which is a RAM-backed filesystem. This isn't the same as caching as a cache means the file also resides on disk. With /dev/shm, which is a tmpfs filesystem, the files exist in memory only. Note that you can mount tmpfs volumes anywhere: mount -t tmpfs none /foo/bar There is just one usually mounted...
What dev folder allows you tell the OS to cache something?
1,532,520,757,000
I do not think that this is Linux's disk cache. In htop, the memory bar is green (not orange for cache) and I removed the files stored in zram. No processes seem to be using a lot of memory. The load was compiling software with its build files stored in zram (PORTAGE_TMPDIR which is /var/tmp/portage in Gentoo), with s...
Short answer: Use discard mount options when mounting file systems or turning on swap created on the Zram devices. Extended: When mounting a file system use discard as a mount option, you can set mount options with -o and options separated with a ,, no space between. It should be supported on most Linux file systems, ...
After a heavy I/O load, and storing many things in Zram, used space is close to total in `free`
1,532,520,757,000
I have just installed Linux Mint about 5 days ago, and then I have upgraded my RAM memory from 8 GB to 12 GB, and I have 4 GB more on the way, so it will get to 16 GB or RAM. The only thing is, I don't understand how the free -g command works. Here's a picture of Stacer, in which I can see my RAM up to 12 GB: But whi...
Your system is fine. You need to add “available” and “used” memory, rather than “free” and “used” memory. You also need to take truncation into account: you have somewhere over 3GiB of memory used (by programs), somewhere over 6GiB of memory completely unused, somewhere over 2GiB of memory used in buffers and caches, ...
Linux Mint RAM Memory - Showing different usage and free space
1,532,520,757,000
I am interested in the totals of the 3 lines. Specifcally, if the "used" values can be counted as what's going on in real time, or if that's just a running total since the OS was started? How does this compare to the vmstat si and so output as opposed to free's representation of swap?
'Used' is real-time (or at least, close to it). It's important to note that the value for 'used' on the first line includes buffered and cached memory, and that even the value for 'used' on the second line includes file-backed (i.e. non-anonymous) pages that can be dropped without swapping if needed. Generally, these ...
How are the values represented with the "free" command
1,532,520,757,000
For a while now on my system browsers crash very often (between 3 times in a row when opening and once every hour). Sometimes the entire browser crashes, sometimes its only one tab. I normally use Firefox but Chromium Browsers crash in seemingly the same way. I assume this happens because of Nvidia proprietary Drivers...
Since it's not your GPU, please test your RAM using either memtest86+ or memtest86 for at least a couple of cycles.
Why do Browsers crash on my machine with Nvidia Drivers?
1,607,669,470,000
I'm learning how to use Message Queue in Linux and I've found a simple example: https://www.geeksforgeeks.org/ipc-using-message-queues/. With the reader and writer in this link, I can read and write messages through the Message Queue on my Ubuntu. Everything is fine. Well, if I'm right, when we write some messages int...
IPC resources aren’t tied to a given process, so they don’t show up in the data displayed by top, ps etc. You can see this in the example you’re referring to: the message queue is created by the writer but deleted by the reader. To monitor IPC resources, you can use lsipc: lsipc will provide an overview, and lsipc -q...
Is RAM usage of IPC a part of the RAM usage of a program
1,607,669,470,000
So i noticed how linux sometimes uses swap memory (located in internal HDD / SSD). When ram is overloaded PC stores some ram data in swap to make things faster it guess. So if you can store ram data in HD can you do the opposite and store HD data in ram (maybe temporary)? I know this is impractical but still...
Can you store files in RAM? Yes you can using something like ramfs (as mentioned in a comment), but this is unrelated to how and why the system swaps. In fact it could happen that some of your files stored in RAM end up swapped into disk. Linux (and Windows) have a concept of virtual memory, where the operating system...
Can We save files in RAM?
1,607,669,470,000
With the performance set aside, is it possible to avoid RAM and use SDCard instead of it in Linux. Linux might be using allocated address space as RAM. Can we ask linux to use SDCard as RAM? I will use class 10 SDcard which is of the highest quality. Thanks in advance.
Yes as long as you don't try to eliminate all RAM. You need some RAM as the CPU needs to access RAM. It is how it works. TLB, and a lot of other stuff have to be in primary memory. In Gnu/Linux you can set up the SD card as swap, and use very little RAM. However this could lead to a lot of wear of the SD card. SD car...
Linux: Replace RAM with SDCard
1,607,669,470,000
In windows, we can enable page heap verification using gflags to catch memory corruption bugs more easily. Is there a similar service/program for Linux and FreeBSD operating systems?
See https://en.wikibooks.org/wiki/Linux_Applications_Debugging_Techniques/Heap_corruption E.g., electric fence will do this. Valgrind will also do this and much more http://valgrind.org/docs/manual/mc-manual.html
Finding memory corruption bugs in Linux and FreeBSD
1,607,669,470,000
Is there a way to get out more out of your limited Ram on a VM? I have a VM running on a cloud hoster and try to optimize a quite low on RAM mashine. I heard, there is a way to compress parts in the memory if all free memory is in use called zram How do I get this running?
As explained on the Zram Wiki: zram (previously called compcache) can create RAM based block devices. It is an experimental (staging) module of the Linux kernel since 3.2. So If you are using a kernel before 3.2 you need to copy the following script (taken from here) to /etc/init.d/zram: ### BEGIN INIT INFO # Provi...
Compress memory on low Ram VM
1,607,669,470,000
I'm trying to monitor the CPU and RAM usage (in % of total for example) of a given process wich may spawn several processes. The parent process is /bin/rscw so I get its pid by ppid_bl=$(ps -ef | grep [b]in/rscw | awk '{print $2}') and then I try something like ps -ppid $ppid_bl S (1) because in man ps it appears -pp...
I have to use two dashes for this parameter, like $ ps --ppid 1 My version: $ ps --version procps-ng version 3.3.4
CPU and RAM monitorization by parent id
1,607,669,470,000
Sometimes my computer starts to behave sluggishly after running too many programs/processes simultaneously, at points almost looking crashed/frozen. Using Debian Linux, is there a way to automatically kill some processes before memory gets too scarce for smooth operation?
Basically, you want a daemon that monitors the free memory, and if it falls below a given threshold, it chooses some process and kills them to free up some memory. while (true) { size_t free_memory = get_free_memory(); if (free_memory < free_memory_threshold) { pid_t pid = choose_a_process_to_kill(); ...
How to make the system automatically kill some processes?
1,607,669,470,000
I think my MacBook with soldered RAM has a RAM issue.  With memtest86+, I figured out which BadRAM pattern I have, but I cannot interpret the result correctly.  How should I read the range to set up the right exclusion in GRUB? Here are my memtest results: BadRAM Patterns --------------- badram=0x0000000058cb4000,0xff...
Yes, you can try it. Check /proc/cmdline to see if it's passed correctly, to make sure Grub doesn't mess with the $ characters, otherwise add \ escape characters. There is also badram support in Grub (GRUB_BADRAM in /etc/default/grub if you use grub-mkconfig). However it's also necessary to test whether it's effective...
BadRAM Range: cannot set up the right range
1,607,669,470,000
I have a Lenovo IdeaPad 3-15ADA6 Laptop, Type 82KR, with Debian 11 Bullseye. I have just installed a brand new RAM chip, Corsair Vengeance 8Gb DDR4 2400MHz, as from Lenovo specifications. If I run sudo lshw I can see all the installed RAM correctly: *-memory description: System Memory physical id: 1 ...
From what I've read, you should be using 8GB DDR4-RAM 3200MHz (PC4-25600) instead of the slower memory you've used
Why did 10 GB of RAM disappear?
1,607,669,470,000
I would like to copy the content of a file (string) to my ram memory. As in copy of a text so I can do paste later. Example: I have a file name: my_pub_key.pub and inside there's big amount of chars. Every time I highlight the text and do copy and later paste - I get partial of the string. Is there a (theoretical) way...
to avoid any installation one can do: cat ~/.ssh/my_pub_key.pub > /dev/clipboard and you'll have it ready for a paste.
how to copy text of file to ram (to do paste later)
1,607,669,470,000
I have 8 gb of ram, ssd and very greedy for ram Android studio/gradle. and sometimes when gradle builds project(eats ram) it hangs all ubuntu(and xubuntu). ui becomes so laggish - mouse cursor moves 1 cm per 10 seconds. i dont know why it happens and it seems that no one knows cause there is a couple questions like mi...
i found out that i had only 2gb file swap and my 8gb swap partition wasn't enabled(it's lame. but i'm new in linux). file partition swap was full on high loading and i assume that an ubuntu freeze was just a lack of virtual memory. i am still not sure about that because i remember that there was still 400-700mb buff/c...
Disable buff/cache linux for fixing ubuntu hangs on full ram
1,607,669,470,000
As we know, cgroups can limit cpu usage of processes. Here is an example: PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 30142 root 20 0 104m 2520 1024 R 99.7 0.1 14:38.97 sh I have a process, whose pid is 30142. I can limit it as below: mkdir -p /sys/fs/cgroup/memory/foo ech...
Control groups are pid-based, and there is no direct way of limiting processes by name. (Since control groups are hierarchical, this makes sense: a group also contains its member processes’ future children, by default, and having them re-attach to another group based on their name would be surprising.) The typical way...
cgroups: Is it possible to limit cpu usage by process name instead of by pid
1,487,415,674,000
Here is the script: TYPE="${BLOCK_INSTANCE:-mem}" awk -v type=$TYPE ' /^MemTotal:/ { mem_total=$2 } /^MemFree:/ { mem_free=$2 } /^Buffers:/ { mem_free+=$2 } /^Cached:/ { mem_free+=$2 } /^SwapTotal:/ { swap_total=$2 } /^SwapFree:/ { swap_free=$2 } END { if (type == "swap") { free=sw...
Awk's printf is treating your trailing % as the start of a fourth format specifier. If you want to print a literal % sign you need %%, for example $ awk 'BEGIN{printf("%.1fG/%.1fG (%.f%%)\n", 1.2, 3.4, 5.6)}' 1.2G/3.4G (6%)
Awk run time error: not enough arguments passed
1,487,415,674,000
This question is two-fold: I have a crappy little netbook with just 4GB of RAM, I've been running Linux on there for a couple of years, with just 4GB of ram. It's functioned well under the circumstances, but freezes from time to time, usually because of Firefox. I've set up a swap partition today, and that's helped d...
Is it possible to use a USB stick as additional RAM, excluding the use of swap partitions? No. From a system's point of view, memory is either RAM (the main memory, physically attached to the processor bus) or swap, the extended memory mapped to another device (usually disk). There is no other type of general memory...
Is it possible to use a USB stick as additional RAM, excluding the use of swap partitions?
1,487,415,674,000
I'm planning to use one of two old computers as a low-volume backup server. The machine will be online and files will be backed up over ssh/rsync. I will do a minimal install of Ubuntu or Debian server. The specifications of the machines are as follows: Pentium3 1GHz Coppermine CPU with two 168-pin SDRAM DIMM slots w...
I'd say that the most important thing for a backup server is reliability, so would tend to go for that machine. You say it's low-volume so the CPU would be idle most of the time anyway.
CPU or RAM better in old machine?
1,487,415,674,000
I have a Debian box, where I am doing some data recovery using ddrescue on a sata ssd. The process has been running for 24 hours, and has 24 to go (at least) in any event, the PC has 16GB ram, and 10GB swap. For some reason, There is 8GB swap in use, and 2GB RAM in use. This seems like an inefficient use of resources....
Swap is being used instead of ram because the memory pushed to swap was inactive, not being used, and likely your ddrescue is pulling in a lot of data that is filling up cache in ram. This is not really an efficiency problem, it should be able to pull the data out of swap fairly quickly when it needs it. It is in swa...
why is all this swap space being used?
1,487,415,674,000
What happens if a Linux, let’s say Arch Linux or Debian, is installed with no swap partition or swap file. Then, when running the OS while almost out of RAM, the user opens a new application. Considering that this new application needs more RAM memory than what’s needed, what will happen? What part of the operating s...
The Linux kernel has a component called the OOM killer (out of memory). As Patrick pointed out in the comments the OOM killer can be disabled but the default setting is to allow overcommit (and thus enable the OOM killer). Applications ask the kernel for more memory and the kernel can refuse to give it to them (becaus...
What happens if a Linux distro is installed with no swap and when it’s almost out of RAM executes a new application? [duplicate]
1,487,415,674,000
I just upgraded from two 2GB RAM cards to two 8GB ram cards. I've read that my laptop (T420) officially supports 8GB but can work with up to 16GB. I'm running free -mh which returns: total used free shared buff/cache available Mem: 7.7G 1.0G 5.3G 143M ...
sudo dmidecode --type 17 would returns physical RAM info.
How to check that ram is plugged in?
1,487,415,674,000
I have a java application that runs on a Linux server with physical memory(RAM) allocated as 12GB where I would see the normal utilization over a period of time as below. sys> free -h total used free shared buff/cache available Mem: 11G 7.8G 1.6G 9.0...
In case available is close to 0, will it end up in a System crash? On testing in one of my servers, where I loaded the memory with almost full as below sys> free -h total used free shared buff/cache available Mem: 11G 11G 135M 25M 187M ...
When to upgrade RAM based on free output [closed]
1,487,415,674,000
I have this question that I need an answer to. What makes programs like st, zathura, sxiv, and feh load instantly and what makes programs like VS Code and Google Chrome load so slowly in low-spec computers? For example, I have a low-spec laptop running Linux Mint. And when I execute st, it instantly opens an st insta...
feh does not do much comparing to Google Chrome. Just compare the files sizes and the number of dependencies: $ ls -l /usr/lib/chromium/chromium -rwxr-xr-x 1 root root 187751032 May 13 05:50 /usr/lib/chromium/chromium $ ls -l $(which feh) -rwxr-xr-x 1 root root 207280 Feb 2 21:03 /usr/bin/feh $ ldd /usr/lib/chromium/...
What makes a program load so fast? [closed]
1,487,415,674,000
I build some software on an armv7 with 1 GB RAM installed. It seems, that some builds need too much RAM: And the build get RIP and with internal compiler error: Killed (program cc1plus). So I am enlarge the swap by adding a swapfile, like it is described here http://www.thegeekstuff.com/2010/08/how-to-add-swap-space/...
echo 100 > /proc/sys/vm/swappiness https://en.wikipedia.org/wiki/Swappiness
Why the system don't swap?
1,487,415,674,000
Since the physical size of the file would be less than the logical file size, is it possible to create a sparse file with a size bigger than the available ram?
Files can naturally be bigger than RAM, sparse or no. I have a terabyte harddisk but not terabytes of RAM. If you meant bigger than the filesystem / partition, then sure, you can create a sparse file that has exabytes instead of terabytes in size, this is only limited by the maximum file size of a given filesystem and...
Can a sparse file go beyond the ram size?
1,487,415,674,000
So I have a Scientific Linux LiveDVD. And I have it installed on a PC that has no hard drives configured and avaliable at all. I want to install some applications that would allow me to configure system before I would be able to install OS. So I wonder: how to create a temporary installation folder that would exist on...
Yum will do that by default in Live mode; anything you install whilst running off a live optical disc is installed to RAM because you are running off of RAM as it is. If you want to do it explicitly, though, you can create a RAM disk: mkdir foo mount -t tmpfs -o size=4096M bar /foo where: mount is the command. -t tm...
How to install applications temporary into RAM on LiveCD?
1,487,415,674,000
As a side project, I am thinking about adding a NTP server to pool.ntp.org. I would like to use CentOS basic, but how much RAM and CPU should I assign to a machine that will only be running ntpd (plus all the basic OS services, of course)?
I've run these services on a machine with 2x1GHz cores with 256MB RAM but I would expect that if this is your only service you have, you would only need something like dual-core 500MHz+ (one would work but needs to be a bit faster) CPU and 128MB RAM.
How much RAM and CPU for a NTP server? [closed]
1,487,415,674,000
TLDR; If /tmp in mounted as tmpfs, in the presence of swap, is there any kind of priority when swapping ? Does tmpfs start to swap before applications ? FULL STORY I have a laptop with 32G of RAM (Debian), and 32G of swap. I plan to mount /tmp with tmpfs. But I am concerned with the behavior if the system needs to swa...
I’m not aware of any priority applied here. Pages will be swapped out based on their level of use — pages which haven’t been used recently will be swapped out first. If that happens to be pages used in a tmpfs, or pages used by applications, doesn’t make any difference. See How does the kernel decide between disk-cach...
Do applications have priority over tmpfs for RAM usage (in the presence of swap)?
1,487,415,674,000
Background: I purchased a new computer, and during the past two months, I experienced the computer freezing, thrice. When it freezes, I have no option other than to reboot the computer. last -x showed: nav tty7 :0 Fri Jun 16 20:36 - crash (00:19) On running Memtest86+, it passed during the f...
A Superuser post with an accepted answer tells you that unless you have ECC ram, disk files can be corrupted. That post was for Windows but the conclusion should hold for any operating system. I don't know of a distribution that does a CRC check of every file after installation as this would add a huge amount of time ...
What files can an XMP-enabled RAM corrupt, if the RAM fails Memtest?
1,487,415,674,000
I ran some commands (in a script to be fast) and got this: $ ps -A | wc -l 513 $ echo "$((`ps -A -o rss |tr "\n" +`0))" 4368208 $ free total used free shared buff/cache available Mem: 5993608 5157844 132848 42616 702916 519028 Swap: 21030892 ...
The kernel itself uses some ram, but most of it is in that 702,916k of buffers/cache.
RAM used by apps doesn't sum up vs free RAM, why?
1,487,415,674,000
I usually monitor my server resource usage. I am using htop for monitoring. When running htop the memory usage is 1.3G, which is fine for me. But I tried to view the memory used by each process. For this, I am using ps command. To view the memory used by MySQL, I am runing ps aux | grep mysqld. It prints these lines: ...
2845500 is the amount of memory allocated by the process, not the amount it’s using. The latter is given by the next column: 387676. Both values are measured in kilobytes.
`ps` showing much higher ram usage than `htop`
1,487,415,674,000
I have been developing a MySQL database that makes some use of BLObs. This has now been transferred on to a virtual machine (VM) in preparation for going fully into the 'cloud'. However some of the larger and more complex queries have caused MySQL to drop out! These were not a problem on my laptop. Investigating thi...
There's not really any meaningful formula here; there's just arbitrary rules of thumb that get thrown around. E.g., "The perceived wisdom seems to be that for servers the ratio of Swap to RAM is lower than for PCs." Perhaps that assumes a gargantuan amount of RAM, as servers are more likely to have. But this is ...
Calculating RAM/Swap Space Requirements [duplicate]
1,487,415,674,000
I have a system with 125G ram available and a swap partition with 4G, which is constantly full. On a disk with 223 GiB available, I would like to increase the swap partition. Is it safe to just swapoff /dev/sda2, extend the partition table for /dev/sda2 and resize the swap file system and turn it back on again? This h...
Assuming you have enough RAM free to absorb the 4GB then it is safe to just swapoff and resize if that's what you want. You can of course also add a second partition and add that too, there's unlikely to be any real loss to having two partitions instead of one. Just remember to add it in /etc/fstab Note that having "t...
Extend Swap partition
1,487,415,674,000
I am trying to mount a filesystem with DAX feature on RAM. I used this answer to load brd module and get /dev/ram0. Then I tried all 3 filesystems that support DAX: ext2, ext4 and xfs. However, when I use -o dax flag with mount, I get this error: wrong fs type, bad option, bad superblock on /dev/ram0, missing codepage...
It seems that DAX support was removed from brd module. There is a patch from 2017.
Mount filesystem with DAX enabled on RAM
1,487,415,674,000
No idea how to create a bash script, without using sudo, that shows Memory Info like 8 x 16384 MB DIMM-1600 MT/s Samsung. number of memory + size of each + type + manufacturer
sudo lshw -class memory | sed -n '/-bank/,$p' | sed -n '/cache/q;p' | egrep "bank|description|product|size|clock|vendor" *-bank:0 description: DIMM DDR4 Synchronous Unbuffered (Unregistered) 3600 MHz (0.3 ns) product: XXXXX vendor: CRUCIAL size: 16GiB clock: 3600M...
How to get memory info without sudo command on bash
1,602,259,652,000
I have a problem with a new RAM that I bought. My system is a Thinkpad T410 with Debian 10 stable with 2+2GB of RAM. Today I replaced a 2GB board with a 8GB. I checked with htop my total amount of RAM and it's correct (9.6GB) but when my pc is stressed (lot of programs open and CPU under stress too) the system suddenl...
I'll leave a solution for anyone that will have my same problem. In my case I was trying to install a 8+2 GB RAM with the 8 GB at 1600 Mhz. My T410 only supports 2,4,8 GB of a single RAM for a maximum of 8GB in total. And as it's not enough, T410 only supports 1066 Mhz and this could cause conflicts as well. Solution:...
Changed RAM and now my system is malfunctioning
1,602,259,652,000
I am trying to know how to enable ZRAM for my PC running Ubuntu. I have heard that the ZRAM is speeding up some laptop and PCs, so will the ZRAM help My PC too? PC specs: CPU: Intel Core 2 Duo E4500 (2) @ 1.770GHz GPU: Intel 965Q Memory: 684MiB / 2992MiB Can someone tell me ...
Just run sudo apt-get install zram-config and everything will be handled for you After that if you need to customize the settings then you can use zramctl or write some options to /dev/zramX
How to Enable ZRAM on PC?
1,602,259,652,000
Using this script taken from this site #!/usr/bin/ksh # Available memory memory=`prtconf | grep Memory | head -1 | awk 'BEGIN {FS=" "} {print $3}'` gb_memory=`echo "scale=2; $memory/1024" | bc -l` # Free memory pagesize=`pagesize` kb_pagesize=`echo "scale=2; $pagesize/1024" | bc -l` sar_freemem=`sar -r 1 1 | tail -1...
As @Fox noted in a comment, it may be ZFS which by default uses free memory to cache IO. There are various tweaks, but just upgrading Solaris may help as they've added a few features to help ZFS performance in Solaris 11. Ref MOS doc: Memory Management Between ZFS and Applications in Oracle Solaris 11.x (Doc ID 1663...
Solaris11: use a lot of ram
1,602,259,652,000
I'm sorry for asking something as elementary, but the information is very confusing and, even when there are ISO recommendations, not everybody follows them. The manufacturer says my laptop has "8GB DDR4 system memory" and I want to set a swap partition with EXACTLY that size + a small margin, but the version of gpart...
The command free -m will give you the size in MiB (2^20 bytes per MiB) and the command free -mega will give you the size of your RAM in MB (10^6 bytes per MB) There are other options: man free You will probably want MiB for gparted, as it doesn't use MB. An alternative to using gparted is to create a swapfile. That ma...
How to conver each GB "manufacturer" RAM to the EXACT MB equivalent gparted uses?
1,602,259,652,000
I have 16GB of RAM with Debian 9 in my notebook but almost all of it is unused by the kernel. It uses only 1GB for buffer/cache. Where can I tell the kernel to use more of the free RAM for caching? My FS is Ext4. Thanks!
The kernel only caches data that has been accessed. If you have not read more than 1GB of data from the disk since the last boot, then it will not have more than 1GB cached.
Where to set kernels buffer/cache size
1,602,259,652,000
My problem If I transfer file with rsync using tapes,or disk(usb,e-sata,firewire) linux hang,no way to resume if not using powerbutton(brutal shutdown!) sysrq-trigger don't work,ssh don't answer,keyboard and screen no input. I have a M5A97 R2.0 Asus board,with 16G ram Crucial. I 've ordered a couple of other ram by ki...
Change ram and..works fine. Transfer of over 2TB completed without panic. So problem was my old ram.
linux hang on transfer with rsync,can be a ram error?
1,602,259,652,000
I'm wondering if our system has lots of free RAM, or if its almost out. I read here regarding MemAvailable but I am wondering how it applies to VirtualBox as I am sure thats the reason the numbers I get from the following commands differ so much. cat /proc/meminfo | grep Mem && free -lg MemTotal: 32771584 kB Mem...
You have 25Gb free; it's all being used as cache. The free output is most telling: total used free shared buffers cached [...] -/+ buffers/cache: 5 25 See http://www.linuxatemyram.com/ for more details.
VirtualBox Host - Ram Question - Mem Free Vs Mem Available - Possible Mem Leak?
1,602,259,652,000
I have a laptop with 8GB of RAM running 4.0.4-2-ARCH. Recently, I installed Android Studio, and bam, my normally pristine system was suddenly stuttering and all out freezing (more than once). Before Android Studio, I comfortably ran SMB, Minidlna, Plex, MySQL, PostgreSQL, Apache and Chrome simultaneously with no issu...
While it may appear you have more than enough RAM, Linux buffers file data in memory. It is also common to place file systems like /tmp in memory to speed up access. If you don't have swap enabled, there are a lot of things that may end up stuck in memory that may prevent caching of frequently accessed files. Your ...
Why and how is swap improving performance, and can I disable it? [closed]
1,602,259,652,000
I have found on web those two command line to see top 10 cpu and ram eating process ram echo " SZ PID RUSER COMMAND";UNIX95= ps -ef -o 'sz pid ruser args' |sort -nr|head -10 cpu echo " SZ PID RUSER COMMAND";UNIX95= ps -ef -o 'sz pid ruser args' |sort -nr|head -10 Someone know a command line to see how much mb of r...
Solution found in a very good script http://www.cfg2html.com/ echo "VSZ(KB) PID RUSER CPU TIME COMMAND" UNIX95= ps -e -o 'vsz pid ruser cpu time args' |sort -nr|head -25
hpux: how much memory process eating?
1,602,259,652,000
we have VM machines (machines are RHEL 7.9), and recently machines RAM memory was update from 32G to 64G is it possible to verify on which date? memory was update?
Your kernel logs at boot should give you the total memory. Did you search through them? See this previous post in stack exchange. On my system, I kind of just shotgun with grep -i ram /var/log/* Bib in comments notes: grep -Ei memory.+available /var/log/* may work better. It does on my test cases. But on RHEL it may w...
how to verify when RAM memory was update on RHEL machine
1,602,259,652,000
I am using nginx + varnish. I noticed that I have ~ 22GB / 32GB in use. I looked in htop and noticed that there are about 170 duplicate varnish processes. Tell me what could be the problem? Where to start looking?
Threads What you're seeing in htop are Varnish treads, not Varnish processes. Varnish only has 2 long running processes: The main process (owned by the varnish user) The worker process (owned by the vcache user) The reason why you're seeing so many of them, is because Varnish wants the system to be responsive enough...
Varnish duplicate process 170 once
1,602,259,652,000
(Manjaro 20, Linux 5.8.3, KDE, this laptop) When reasonably much is going on in my system, the RAM and swap usage often goes much higher than it should. For example currently I have a VM with a VM in it running and two instances of Minecraft, also some smaller stuff like music. That might sound like much, but my CPU i...
Following comments, ps aux --sort -vsize helped locating the big spender, baloo. I'll propose disabling it; it's an index service, perhaps you can live without it. Control commands: balooctl status balooctl disable Edit ~/.config/baloofilerc Indexing-Enabled=false (perhaps needs reboot) You could also try to purge and...
High RAM and swap usage out of seemingly nowhere
1,427,416,989,000
In order to understand another answer (by glenn jackman): find / -type d -print0 | while read -r -d '' dir; do ls -ltr "$dir" | sed '$!d'; done the first step is to understand the usage of the option -r of the read command. First, I thought, it would be sufficient to simply execute man read to look up the meaning of...
There is no stand-alone read command: instead, it is a shell built-in, and as such is documented in the man page for bash: read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]     ︙ -r Backslash does not act as an escape character.  The backslash is consi...
What is the meaning of read -r?
1,427,416,989,000
I read that it is bad to write things like for line in $(command), the correct way seem to be instead: command | while IFS= read -r line; do echo $line; done This works great. But what if what I want to iterate on is the contents of a variable, not the direct result of a command? For example, imagine that you create ...
In modern shells like bash and zsh, you have a very useful `<<<' redirector that accepts a string as an input. So you would do while IFS= read -r line ; do echo $line; done <<< "$variable" Otherwise, you can always do echo "$variable" | while IFS= read -r line ; do echo $line; done
Iterating over multiple-line string stored in variable
1,427,416,989,000
How do I get read and write IOPS separately in Linux, using command line or in a programmatic way? I have installed sysstat package. Please tell me how do I calculate these separately using sysstat package commands. Or, is it possible to calculate them using file system? ex: /proc or /sys or /dev
iostat is part of the sysstat package, which is able to show overall iops if desired, or show them separated by reads/writes. Run iostat with the -d flag to only show the device information page, and -x for detailed information (separate read/write stats). You can specify the device you want information for by simply...
How to get total read and total write IOPS in Linux?
1,427,416,989,000
With ksh I'm using read as a convenient way to separate values: $ echo 1 2 3 4 5 | read a b dump $ echo $b $a 2 1 $ But it fails in Bash: $ echo 1 2 3 4 5 | read a b dump $ echo $b $a $ I didn't find a reason in the man page why it fails, any idea?
bash runs the right-hand side of a pipeline in a subshell context, so changes to variables (which is what read does) are not preserved — they die when the subshell does, at the end of the command. Instead, you can use process substitution: $ read a b dump < <(echo 1 2 3 4 5) $ echo $b $a 2 1 In this case, read is run...
In bash, read after a pipe is not setting values
1,427,416,989,000
In some Bourne-like shells, the read builtin can not read the whole line from file in /proc (the command below should be run in zsh, replace $=shell with $shell with other shells): $ for shell in bash dash ksh mksh yash zsh schily-sh heirloom-sh "busybox sh"; do printf '[%s]\n' "$shell" $=shell -c 'IFS= read x </p...
The problem is that those /proc files on Linux appear as text files as far as stat()/fstat() is concerned, but do not behave as such. Because it's dynamic data, you can only do one read() system call on them (for some of them at least). Doing more than one could get you two chunks of two different contents, so instead...
Why some shells `read` builtin fail to read the whole line from file in `/proc`?
1,427,416,989,000
I have a script which connects to a remote server and check if some package is installed: ssh root@server 'bash -s' < myscript.sh myscript.sh: OUT=`rpm -qa | grep ntpdate` if [ "$OUT" != "" ] ; then echo "ntpdate already installed" else yum install $1 fi This example could be simplified. Here is myscript2.sh...
Try something like this: $ ssh -t yourserver "$(<your_script)" The -t forces a tty allocation, $(<your_script) reads the whole file and in this cases passes the content as one argument to ssh, which will be executed by the remote user's shell. If the script needs parameters, pass them after the script: $ ssh -t yours...
Bash: interactive remote prompt
1,427,416,989,000
I have a use case where I need to read in multiple variables at the start of each iteration and read in an input from the user into the loop. Possible paths to solution which I do not know how to explore -- For assignment use another filehandle instead of stdin Use a for loop instead of ... | while read ... ... I do...
If I got this right, I think you want to basically loop over lists of values, and then read another within the loop. Here's a few options, 1 and 2 are probably the sanest. 1. Emulate arrays with strings Having 2D arrays would be nice, but not really possible in Bash. If your values don't have whitespace, one workarou...
Use read as a prompt inside a while loop driven by read?
1,427,416,989,000
In zsh, running the command read -p 'erasing all directories (y/n) ?' ans, throws the error, read: -p: no coprocess But in bash, it prints a prompt. How do I do this in zsh?
You can still use read, you just need to print a prompt first. In zsh, -p indicates that input should be read from a coprocess instead of indicating the prompt to use. You can do the following instead, which is POSIX-compliant: printf >&2 '%s ' 'erase all directories? (y/n)' read ans Like for ksh/zsh's read 'var?prom...
read command in zsh throws error
1,427,416,989,000
How do I handle the backspaces entered, it shows ^? if tried & how read counts the characters, as in 12^?3 already 5 characters were complete(though all of them were not actual input), but after 12^?3^? it returned the prompt, weird. Please help! -bash-3.2$ read -n 5 12^?3^?-bash-3.2$
When you read a whole line with plain read (or read -r or other options that don't affect this behavior), the kernel-provided line editor recognizes the Backspace key to erase one character, as well as a very few other commands (including Return to finish the input line and send it). The shortcut keys can be configure...
How to handle backspace while reading?
1,427,416,989,000
I need to run a script by piping it through bash with wget(rather than running it directly with bash). $ wget -O - http://example.com/my-script.sh | bash It's not working because my script has read statements in it. For some reason these don't work when piping to bash: # Piping to bash works in general $ echo 'hi' hi...
read reads from standard input. But the standard input of the bash process is already taken by the script. Depending on the shell, either read won't read anything because the shell has already read and parsed the whole script, or read will consume unpredictable lines in the script. Simple solution: bash -c "$(wget -O ...
Piping a script with "read" to bash
1,427,416,989,000
I'm used to bash's builtin read function in while loops, e.g.: echo "0 1 1 1 1 2 2 3" |\ while read A B; do echo $A + $B | bc; done I've been working on some make project, and it became prudent to split files and store intermediary results. As a consequence I often end up shredding single lines ...
It's because the part where you use the vars is a new set of commands. Use this instead: head somefile | { read A B C D E FOO; echo $A $B $C $D $E $FOO; } Note that, in this syntax, there must be a space after the { and a ; (semicolon) before the }.  Also -n1 is not necessary; read only reads the first line. For bett...
Use bash's read builtin without a while loop
1,427,416,989,000
I can't figure this out. I need to look at every line in a file and check whether it matches a word that is given in a variable. I started with command read, but I don't know what I am supposed to use after that. I tried grep, but I probably used it wrongly. while read line; do if [ $condition ] ;then echo "ok" fi...
Here's a quickie for you, simply what we're doing is Line 1: While reading file into variable line Line 2: Match a regex, echo the $line if matching the word "bird" echo that line. Do whatever actions you need here, in this if statement. Line 3: End of while loop, which pipes in the file foo.text #!/bin/bash while rea...
Read lines and match against pattern
1,427,416,989,000
The bash man page says the following about the read builtin: The exit status is zero, unless end-of-file is encountered This recently bit me because I had the -e option set and was using the following code: read -rd '' json <<EOF { "foo":"bar" } EOF I just don't understand why it would be desirable to exi...
read reads a record (line by default, but ksh93/bash/zsh allow other delimiters with -d, even NUL with zsh/bash) and returns success as long as a full record has been read. read returns non-zero when it finds EOF while the record delimiter has still not been encountered. That allows you do do things like while IFS= re...
For what purpose does "read" exit 1 when EOF is encountered?
1,427,416,989,000
I have a local machine which is supposed to make an SSH session to a remote master machine and then another inner SSH session from the master to each of some remote slaves, and then execute 2 commands i.e. to delete a specific directory and recreate it. Note that the local machine has passwordless SSH to the master an...
Consider that && is a logical operator. It does not mean "also run this command" it means "run this command if the other succeeded". That means if the rm command fails (which will happen if any of the three directories don't exist) then the mkdir won't be executed. This does not sound like the behaviour you want; if ...
Multiple commands during an SSH inside an SSH session
1,427,416,989,000
I need to write a shell script that find and print all files in a directory which starts with the string: #include. Now, I know how to check if a string is in the file, by using: for f in `ls`; do if grep -q 'MyString' $f; then: #DO SOMETHING fi but how can I apply this to the first line? I thought t...
It is easy to check if the first line starts with #include in (GNU and AT&T) sed: sed -n '1{/^#include/p};q' file Or simplified (and POSIX compatible): sed -n '/^#include/p;q' file That will have an output only if the file contains #include in the first line. That only needs to read the first line to make the ch...
how to check if the first line of file contain a specific string? [duplicate]
1,427,416,989,000
I have this while loop and here-document combo which I run in Bash 4.3.48(1) and I don't understand its logic at all. while read file; do source ~/unwe/"$file" done <<-EOF x.sh y.sh EOF My question is comprised of these parts: What does the read do here (I always use read to declare a variable and assign its...
The read command reads from its standard input stream and assigns what's read to the variable file (it's a bit more compicated than that, see long discussion here). The standard input stream is coming from the here-document redirected into the loop after done. If not given data from anywhere, it will read from the ...
A while loop and an here-document - what happens when?
1,427,416,989,000
General problem I want to write a script that interacts with the user even though it is in the middle of a chain of pipes. Concrete example Concretely, it takes a file or stdin, displays lines (with line numbers), asks the user to input a selection or line numbers, and then prints the corresponding lines to stdout. Le...
Using /proc/$PPID/fd/0 is unreliable: the parent of the selector process may not have the terminal as its input. There is a standard path that always refers to the current process's terminal: /dev/tty. nl "$INPUT" >/dev/tty read -p"Select options: " </dev/tty or exec </dev/tty >/dev/tty nl "$INPUT" read -p"Select opt...
How to read user input when using script in pipe
1,427,416,989,000
The following commands seem to be roughly equivalent: read varname varname=$(head -1) varname=$(sed 1q) One difference is that read is a shell builtin while head and sed aren't. Besides that, is there any difference in behavior between the three? My motivation is to better understand the nuances of the shell and key ...
Neither efficiency nor builtinness is the biggest difference. All of them will return different output for certain input. head -n1 will provide a trailing newline only if the input has one. sed 1q will always provide a trailing newline, but otherwise preserve the input. read will never provide a trailing newline, and...
Is there a difference between read, head -1, and sed 1q?
1,427,416,989,000
I want to simply wait for the user to acknowledge a message by pressing Return. In bash, I am able to call $ read $ However, in sh (dash in my case), I get $ read sh: 1: read: arg count $ It seems like I must provide an argument? Where does that difference come from?
The standard read utility takes at least one variable's name. Some shell's read implementation uses a default variable, like REPLY, to store the read data if no name is supplied, but dash, aiming to be a POSIX compliant shell, does not (as it's not required to do so by the standard). The equivalent in the dash shell ...
Error sh: 1: read: arg count
1,427,416,989,000
I have a bash script that is named reader. It reads user input: #!/bin/bash read -p "What is your name?" username echo "Hello, ${username}" Running the script by source reader (EDIT: from the zsh shell), I get the error reader:read:2: -p: no coprocess. It doesn't give this error when I run it as ./reader. Other rea...
When you use source, it's the current shell that reads the file, not the shell mentioned on the #! line. And I assume that your shell is either zsh or ksh93 which uses read -p to read from a co-process. An example of that in ksh93: cat /etc/passwd |& while IFS=":" read -p user rest; do printf 'There is a user ca...
"no coprocess" error when using read [duplicate]
1,427,416,989,000
The output of the command below is weird to me. Why does it not give me back element 5? $ echo '0,1,2,3,4,5' | while read -d, i; do echo $i; done 0 1 2 3 4 I would expect '5' to be returned as well. Running GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu). Adding a comma works, but my input data does not...
With read, -d is used to terminate the input lines (i.e. not to separate input lines). Your last "line" contains no terminator, so read returns false on EOF and the loop exits (even though the final value was read). echo '0,1,2,3,4,5' | { while read -d, i; do echo "$i"; done; echo "last value=$i"; } (Even with -d, re...
Bash Read: Reading comma separated list, last element is missed
1,427,416,989,000
I know this question has been already asked & answered, but the solution I found listens for space and enter: while [ "$key" != '' ]; do read -n1 -s -r key done Is there a way (in bash) to make a script that will wait only for the space bar?
I suggest to use only read -d ' ' key. -d delim: continue until the first character of DELIM is read, rather than newline See: help read
Press SPACE to continue (not ENTER)
1,427,416,989,000
If I try to execute read -a fooArr -d '\n' < bar the exit code is 1 -- even though it accomplishes what I want it to; put each line of bar in an element of the array fooArr (using bash 4.2.37). Can someone explain why this is happening I've found other ways to solve this, like the ones below, so that's not what I'm...
What needs to be explained is that the command appeared to work, not its exit code '\n' is two characters: a backslash \ and a letter n. What you thought you needed was $'\n', which is a linefeed (but that wouldn't be right either, see below). The -d option does this: -d delim continue until the first character of...
read -a array -d '\n' < foo, exit code 1
1,427,416,989,000
(For simplicity I'll assume the file to read is the first argument - $1.) I can do what I want externally with: tempfile=$(mktemp) awk '/^#/ {next}; NF == 0 {next}; {print}' "$1" > $tempfile while read var1 var2 var3 var4 < $tempfile; do # stuff with var1, etc. done However, it seems absurd to need to call awk ever...
You don't need a tempfile to do this, and sed (or awk) are far more flexible in comment processing than a shell case statement. For example: configfile='/opt/myconfigfile.txt' [ $# -gt 0 ] && [ -r "$1" ] && configfile="$1" sed -e 's/[[:space:]]*#.*// ; /^[[:space:]]*$/d' "$configfile" | while read var1 var2 var3 ...
How to make bash built-in "read" ignore commented or empty lines?
1,427,416,989,000
This script takes the user input line after line, and executes myfunction on every line #!/bin/bash SENTENCE="" while read word do myfunction $word" done echo $SENTENCE To stop the input, the user has to press [ENTER] and then Ctrl+D. How can I rebuild my script to end only with Ctrl+D and process the line wher...
To do that, you'd have to read character by character, not line by line. Why? The shell very likely uses the standard C library function read() to read the data that the user is typing in, and that function returns the number of bytes actually read. If it returns zero, that means it has encountered EOF (see the read(2...
How to read the user input line by line until Ctrl+D and include the line where Ctrl+D was typed
1,427,416,989,000
I found some code for reading input from a file a while ago, I believe from Stack Exchange, that I was able to adapt for my needs: while read -r line || [[ -n "$line" ]]; do if [[ $line != "" ]] then ((x++)) echo "$x: $line" # <then do something with $line> fi done < "$1" I'm reviewing...
[[ -n "$line" ]] tests if $line (the variable just read by read) is not empty. It's useful since read returns a success if and only if it sees a newline character before the end-of-file. If the input contains a line fragment without a newline in the end, this test will catch that, and the loop will process that final ...
What does `while read -r line || [[ -n $line ]]` mean?
1,427,416,989,000
With the below function signature ssize_t read(int fd, void *buf, size_t count); While I do understand based off the man page that on a success case, return value can be lesser than count, but can the return value exceed count at any instance?
A call to read() might result in more data being read behind the scenes than was requested (e.g. to read a full block from storage, or read ahead the following blocks), but read() itself never returns more data than was requested (count). If it did, the consequence could well be a buffer overflow since buf is often si...
Can read() return value exceed the count value?
1,427,416,989,000
I have a following small bash script var=a while true : do echo $var sleep 0.5 read -n 1 -s var done It just prints the character entered by the user and waits for the next input. What I want to do is actually not block on the read, i.e. every 0.5 second print the last character entered by the user. Whe...
From help read: -t timeout time out and return failure if a complete line of input is not read within TIMEOUT seconds. The value of the TMOUT variable is the default timeout. TIMEOUT may be a fractional number. If TIMEOUT is 0, read returns immediately, without trying to read an...
bash: non blocking read inside a loop
1,427,416,989,000
My script (should) acts differently, depending on the presence of the data in the input stream. So I can invoke it like this: $ my-script.sh or: $ my-script.sh <<-MARK Data comes... ...data goes. MARK or: $ some-command | my-script.sh where two last cases should read the data, while first case should notice...
No, read -t 0 will not read any data. You are reading the wrong manual. The man read will give the manual of a program in PATH called read. That is not the manual for the builtin bash read. To read bash man page use man bash and search for read [-ers] or simply use: help read Which contains this (on version 4.4): If...
Why bash "read -t 0" does not see input?
1,427,416,989,000
The command df . can show us which device we are on. For example, me@ubuntu1804:~$ df . Filesystem 1K-blocks Used Available Use% Mounted on /dev/sdb1 61664044 8510340 49991644 15% /home Now I want to get the string /dev/sdb1. I tried like this but it didn't work: df . | read a; read a b; echo "$a", th...
The main problem here is grouping the commands correctly. Subshells are a secondary issue. x|y will redirect the output of x to the input of y Yes, but x | y; z isn't going to redirect the output of x to both y and z. In df . | read a; read a b; echo "$a", the pipeline only connects df . and read a, the other comman...
Why must I put the command read into a subshell while using pipeline [duplicate]
1,427,416,989,000
File.tsv is a tab delimited file with 7 columns: cat File.tsv 1 A J 1 2 B K N 1 3 C L O P Q 1 The following reads File.tsv which is tab delimited file with 7 columns, and stores the entries in an Array A. while IFS=$'\t' read -r -a D; do A=("${A[@]}" "${D[i]}" "${D[$(...
As I said in my comments, this is not a job for a shell script. bash (and similar shells) are for co-ordinating the execution of other programs, not for processing data. Use any other language instead - awk, perl, and python are good choices. It will be easier to write, easier to read and maintain, and much faster....
Read file and store as array without skipping empty strings
1,427,416,989,000
How can I give space " " as input in shell script ? Ex : echo " Enter date for grep... Ex: Oct 6 [***Double space is important for single date***] (or) Oct 12 " read mdate echo $mdate I get the output as Oct 6 but I want Oct 6.
You already have Oct  6 in $mdate, your problem is that you're expanding it when printing. Always use double quotes around variable substitutions. Additionally, to retain leading and trailing whitespace (those are stripped by read), set IFS to the empty string. IFS= read -r mdate echo "$mdate" The -r (raw) option to ...
Read space as input in shell script [duplicate]
1,427,416,989,000
I'm not sure how to explain the problem in general, so I'll just use this example: #!/bin/bash cleanup() { rm "$myfifo" rm "$mylock" kill '$(jobs -p)' } writer() { for i in $(seq 0 100); do echo "$(date -R) writing \"$i\"." echo "$i" > "$myfifo" done } reader() { while true; ...
Letting read timeout read timeout actually works. The problem here is that opening a FIFO in reading mode blocks until the FIFO is opened in writing mode. And in this case, this is not read that is blocked, this is bash, when redirecting your FIFO to stdin. Once some other process opens the FIFO for write, bash will s...
read timeout parameter (-t) not working?
1,427,416,989,000
I have a long running Bash script that I don't want to run as root, but it needs root access periodically throughout. I solved this by asking for the user for the root password using sudo -v and then I backgrounded a process that would loop and reset the sudo timer using sudo -n true I then started to have weird pr...
I get the same behaviour with: sleep 1 && true < /dev/tty & read var sudo opens /dev/tty to query the current foreground process group, that causes the read() system call made by bash's read to return with EAGAIN with Ubuntu 18.04's Linux kernel 4.15.0-45-generic and 4.18.0-14-generic at least causing the read utili...
Bash: how can I run `sudo -n true` in the background without interfering with `read`?
1,427,416,989,000
I want to download a provisioning script that reads some configuration parameters via read, and execute it: curl http://example.com/provisioning.sh | sh The problem is, that the read command in the script is call with the -i parameter to provide a default: read -p "Name: " -i joe name echo $name If I download the sc...
When you pipe the output of curl into sh you're making the script text be standard input of the shell, which takes it in as commands to run. After that, there's nothing left to read. Even if it were to try, it wouldn't get anything from the terminal input, because it's not connected to it. The pipe has replaced standa...
Why does the read command not take interactive options when run by sh?