Linux Lite Forums

Development => Scripting and Bash => Topic started by: bitsnpcs on September 21, 2018, 11:55:58 AM

Title: ls /dev
Post by: bitsnpcs on September 21, 2018, 11:55:58 AM
Hello,

In Chapter 15 of , The Linux Command Line, there is a command -

Code: [Select]
sudo tail -f /var/log/messages
It should produce a list and then a SD card is added , it is an example of how the kernel will notice the device and probe it. I can follow the example in the book.
When I run this command (which is not an exercise in the book but I wanted to see it in action) I cannot get a result in terminal myself to then add a USB stick and watch this in action. Maybe the path needs to be different ?

Earlier in the Chapter I had read this -
"quote of Mr.Shotts - First let's look at how the system names devices. If we list the contents of the /dev directory (where all devices live), we can see that there are lots and lots of devices:
Code: [Select]
ls /dev "

This gave me an idea to experiment using the above command, I was trying this below code to determine newly added device names by comparison -

Code: [Select]
ls /dev/sd*My belief was it would show only those with sd naming using the wildcard *, I had learned previously in earlier chapters of "The Linux Command Line" about sd,  and about using wildcard.

Below is a screenshot of my output, and source of my question

(https://preview.ibb.co/dT0EZz/Screenshot_2018_09_21_15_40_46.png)

As you can see I ran the code , I then inserted a USB stick and used up arrow on keyboard to reuse the same code and run it again, thus allowing for a comparison of before and after adding the USB stick.
It produced 2 new results the /dev/sdb and the /dev/sdb1 rather than the 1 new result I was expecting, why is this ?
Title: Re: ls /dev
Post by: Jerry on September 21, 2018, 12:46:46 PM
I use dmesg -wH for freshly plugged in devices.

Sent from my Mobile phone using Tapatalk
Title: Re: ls /dev
Post by: bitsnpcs on September 21, 2018, 12:49:35 PM
@Jerry Thank You :)
Title: Re: ls /dev
Post by: Jerry on September 21, 2018, 06:47:32 PM
No problem :)

Sent from my Mobile phone using Tapatalk

Title: Re: ls /dev
Post by: supergamer on September 21, 2018, 09:34:13 PM
Quote
As you can see I ran the code , I then inserted a USB stick and used up arrow on keyboard to reuse the same code and run it again, thus allowing for a comparison of before and after adding the USB stick.It produced 2 new results the /dev/sdb and the /dev/sdb1 rather than the 1 new result I was expecting, why is this ?



My understanding on why the 2 new devices might be rudimentary but it is how I keep things straight.


In the /dev folder it shows the devices as well as the partitions (partitions being treated as a devices also). So you see the /dev/sda (device) and the /dev/sda1 (partition) as well as the new devices like the new usb device which is /dev/sdb (device) and the partition /dev/sdb1 (partition)
Title: Re: ls /dev
Post by: bitsnpcs on September 21, 2018, 09:52:10 PM
Thank You @supergamer  :) for explaining .


Title: Re: ls /dev
Post by: Moltke on September 22, 2018, 07:51:34 AM
Quote
As you can see I ran the code , I then inserted a USB stick and used up arrow on keyboard to reuse the same code and run it again, thus allowing for a comparison of before and after adding the USB stick.
It produced 2 new results the /dev/sdb and the /dev/sdb1 rather than the 1 new result I was expecting, why is this ?

@bitsnpcs  I'm not sure what you're trying to do, but it seems that you want to ls into a usb stick? if so, then I think the correct path would be run/media/bitsnpcs, like so:
Code: [Select]
$ ls /run/media/bitsnpcs and then your usb stick should appear in the list just like mine - MOK - does as you can see in the image bellow. 

(http://i66.tinypic.com/10dh5k4.jpg)

You might want to read here: http://www.tldp.org/LDP/Linux-Filesystem-Hierarchy/html/dev.html

Hope this helps! :)
Title: Re: ls /dev
Post by: bitsnpcs on September 22, 2018, 10:26:43 AM
I'm not sure what you're trying to do, but it seems that you want to ls into a usb stick?
Hope this helps! :)
@Moltke thank you  :) I have read the info on the link you gave me, it was helpful.

The answer by @supergamer is what I needed to know, I cannot mark things solved in this section of forum.

I am not trying to do something at this stage, just experimenting.

What I was curious about, my motivation, was how a GUI only displays the most recently mounted storage device, as the output option field, or how to make a GUI do this.
and
if I could use this command ls /dev/sd* by attaching it to a button in a GUI to achieve similar type of result.

I understand from @supergamer explanation why this did not work in the way I expected, and I also learned some new and useful information on the structure and use from you both. :)
Title: Re: ls /dev
Post by: Moltke on September 22, 2018, 04:10:03 PM
Glad to help @bitsnpcs

Quote
What I was curious about, my motivation, was how a GUI only displays the most recently mounted storage device, as the output option field, or how to make a GUI do this and if I could use this command ls /dev/sd* by attaching it to a button in a GUI to achieve similar type of result.

Hmmm...I think you could achieve that in python. Are you trying to create/creating a GUI for some specific purpose? May I suggest this program: http://page.sourceforge.net/  I've been playing around with it since last August. It teaches you how to create GUIs using python. From it's website: "PAGE is a cross-platform drag-and-drop GUI generator, bearing a resemblance to Visual Basic. It allows one to easily create GUI windows containing a selection of Tk and ttk widgets. Required are Tcl/Tk 8.6 and Python 2.7+.  PAGE springs from Virtual Tcl, a Tcl/Tk program, forked to generate Python modules that realizes the desired GUI. Tcl is required for running PAGE but is not required for executing the generated Python code." It's not perfect though, I found a bug while using it and reported to it's developer. It seems that the created GUIs won't show properly under python 3.6 - some buttons aren't visible -  wich is the one installed in my system, I had to install python2 so it works as expected. Also, since I've read you're learning python - and so am I by the way  ;D - you might find insteresting this too: https://thonny.org/ it's a "python IDE for begginers" as advertised on its website. Both programs are really light on resources and download sizes are really low, less than 5mb both I think. Page runs as a script so there's no need to install anything. Instructions for installing Thonny are on the link above.

Hope you find this info helpful! :)
Title: Re: ls /dev
Post by: bitsnpcs on September 22, 2018, 09:07:48 PM
Thank you for the links @Moltke  :)
No not trying to create anything at the moment, I am working through the book, "The Linux Command Line", unsure how many years ago I began it, I began to use Linux (Linux Lite right from the very start) 4 years ago from July 2018. But only started to use Linux and no Windows after a few of those years.
I learn some bits then do other things. When I feel ready then I learn some more. I am just beginning Chapter 17.

I use LL, and Gedit for Python coding, I then test the Python in the terminal before making the GUI, I build the GUI afterwards by editing and typing it in to the Python code in its file.
If you have not seen it this was my first completed Python app and GUI I made, I done it on LL using Gedit, Terminal, Python, and Tkinter. I am really pleased I was able to finish the first one because it will encourage me in future projects, not to give up easily.


https://www.youtube.com/watch?v=yLAAlE5FKoo

Overall in the chapter of book I learned about the storage commands to -
1. make files or folders in to an image
2. command to burn that image/ISO
3. how to clone hard drive to another hard drive
4. how to view what occurs when device is added to the system.

Later that night I was listening to music and looking at the chapter index of contents for next few chapters, a future one is about "archives and backups", my mind thought, you have already learned about backup software, then the thought of commands 1thru 4 and how it may not be too difficult the extra things to learn to make this in Python into a backup software, for files/directories, cloning hard drives, and output it to external media, like portable hard drive or flash drive for files and directories.

Later I thought maybe as a stepping stone to that making an app GUI for burning ISO to disc, or saving to USB could be a practice run, but to make it final /usable gui on its own in case someone liked it or wanted to use it in part of another project.

It was just thoughts of the basic outline of what was needed.

You can get The Linux Command line as pdf free from the official site http://linuxcommand.org/tlcl.php
Title: Re: ls /dev
Post by: Moltke on September 23, 2018, 08:15:56 AM
That GUI looks really good! Nice job @bitsnpcs  :)

Quote
No not trying to create anything at the moment, I am working through the book, "The Linux Command Line", unsure how many years ago I began it...You can get The Linux Command line as pdf free from the official site http://linuxcommand.org/tlcl.php (http://linuxcommand.org/tlcl.php)
I see. I too started reading that book a while ago and for some reason stopped doing it, guess I got stuck at that moment. Thanks for the link by the way.

Quote
I use LL, and Gedit for Python coding
I used to use gedit too, then tried geany, they both are fine but then I discovered sublime text and find it really nice; lightwight, handy features, easy to use. In the past I've used kate (https://kate-editor.org/) even in windows 7, which is a great editor but now I try to avoid having those kde dependencies and who knows, sometimes I fell like installing it  ::)  Althought, the text editor I use the most is nano, yeah nano all the way. Now that I think of it, nano's the reason I never really care too much for text editors.


If you fell like trying sublime text, here are the steps for installing it:


First, open a terminal and type
Code: [Select]
$ wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -


Code: [Select]
$ echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list

Code: [Select]
$ sudo apt-get update

Code: [Select]
$ sudo apt-get install sublime-text


Or, you can simply read more about it on its website http://www.sublimetext.com/


Cheers! :)
Title: Re: ls /dev
Post by: trinidad on September 23, 2018, 11:31:01 AM
@Moltke wrote: "text editor I use the most is nano, yeah nano all the way"
I agree. Use Nano a lot myself for BASH stuff, and whatever other editor is available depending on the OS when it's necessary to be out of the CLI, and I use only Gvim for other code bases like ruby and js. I don't know if it's an attempt at a teaching method, but in a lot of tutorials I see text editors recommended for basically no particularly important reason when nano would be the easiest. Small changes might as well use a small editor.

TC
Title: Re: ls /dev
Post by: bitsnpcs on September 23, 2018, 01:57:41 PM
Thank You @Moltke  :)   it is on Github, if you want, I made gui in way so I (and others) can make other GUI from this easily by copy/paste and edit.

Earlier I made some Gimp edits to try and better show how the thought image and book commands arrived in 1 thought. It took me a lot longer to try and do this.

Maybe it helps someone if it is interesting, it is not a project, or meant to be accurate, it is just showing the process of my thought as images when learning.


The image/thought was based on Systemback as this is the only backup software my eyes had seen.

(https://preview.ibb.co/cuJLe9/bubl1.png)

(https://preview.ibb.co/kQt62U/bubl2.png)

(https://image.ibb.co/jRnG2U/bubl3.png)

(https://image.ibb.co/dxH5wp/bubl4.png)

The image didn't have the highlight, I just use it to show the description below of commands from book and the ideas of how I thought they might be able to be used from a beginner perspective, but likely wrong lol.

1 -  ls -t /directory/of/images       display image filenames of backups made of HOME at #3, and list by date order.

2 - ls /dev/sd*    output destination box, drop down menu for selection of sd* locations

3 - ??  needs command to create an image file from collection of HOME directory contents

4 - dd if=/dev/sdb of=flash_drive.img        need to change command to make image of entire OS not of the example flash_drive

5 - ??  run install media from #4

6 - dd if=input_file of=output_file [bs=block_size [count=blocks]]         where input file is output of/ or stored image of  #4

7 - sudo fsck /location/of/file system          file system check and repair

8 - sudo apt-get update
     sudo apt-get upgrade

9 - add embedded text window, mirroring the terminal output inside the GUI from #6 so any errors are visible.


@Moltke maybe now you can see why I said it was just thoughts based on the commands as I don't know enough to do this, many others would know though.
After the image thought, in popped its description thought -

"Bubl is a blend of LL, Cli, Python and Tk, cooked at 420F and seasoned with Love :) "
Title: Re: ls /dev
Post by: Moltke on September 23, 2018, 02:45:52 PM
@Moltke wrote: "text editor I use the most is nano, yeah nano all the way"
I agree. Use Nano a lot myself for BASH stuff, and whatever other editor is available depending on the OS when it's necessary to be out of the CLI, and I use only Gvim for other code bases like ruby and js. I don't know if it's an attempt at a teaching method, but in a lot of tutorials I see text editors recommended for basically no particularly important reason when nano would be the easiest. Small changes might as well use a small editor.

TC


@trinidad  Yeah, nano's the one I always use the most. I very often find myself typing
Code: [Select]
$ nano somefile in a terminal. I'm so used to it and have learned its key shortcuts...well most of them  8) Vim, Vi, Gvim I've always wanted to learn how to use Vi/Vim since I read a lot of articles claiming its not just one more editor but THE EDITOR LOL, but its "user unfriendliness" makes me always type the one Vi/Vim command I ever learnt :q!  ;D

@bitsnpcs I can only say: WOW! Nicely done girl! Like I said in a previous post I'm just learning how to create GUIs with python  ;D using those two programs I told you about.
Title: Re: ls /dev
Post by: Jerry on September 23, 2018, 02:53:19 PM
nano ftw :)

Sent from my Mobile phone using Tapatalk

Title: Re: ls /dev
Post by: Moltke on September 23, 2018, 05:15:09 PM
nano ftw :)

Sent from my Mobile phone using Tapatalk

What does ftw stand for @Jerry ? I googled for it and found some curious and fun meanings:

forget the world, for the worms, full throttle workshop, forever together whenever (this one I kind of like it :) ), face the world, florida tax watch, for the wolf,    Forschungszentrum Telekommunikation Wien, for the wii, for the weak, free the weed, fight to win, feel the wrath, for the win, follow the way, **** the world (I don't know why but I suspect this is it) and a few others.  ;D
Title: Re: ls /dev
Post by: bitsnpcs on September 23, 2018, 05:29:23 PM
 "fsck the world"
Title: Re: ls /dev
Post by: firenice03 on September 23, 2018, 08:50:41 PM
My 2 cents...
"For the Win"


 8) 8) 8) 8)
Title: Re: ls /dev
Post by: Moltke on September 23, 2018, 11:32:51 PM
"fsck the world"

I think that may be it.

My 2 cents...
"For the Win"

 8) 8) 8) 8)

I thought of this one too ;D